I need to make a UISlider
in my iOS App with the value of the slider in the handle.
Demo image of what I mean:
Is there a pod that could do it?
I need to make a UISlider
in my iOS App with the value of the slider in the handle.
Demo image of what I mean:
Is there a pod that could do it?
You dont need neither any third party control nor you will have to create a slider on your own. You can still use the UISlider and customise it as per your need :)
Step 1:
As we can see we need to set the colour for minimum track and as it is not default white isn't it ??? Its somewhat orange, I dont know exact coolor of it hence am setting it to red. You set whatever colour you want :)
But UISlider's
setMinimumTrackImage
expects a UIImage not colour. So lets create a UIImage from colour. Am creating it as a lazy variable, because I want it to be created only once :)Code is pretty simple. I believe no need to explain that :)
Step 2 :
From your image, we can conclude that the thumb image of slider needs to be custom. But we can't create it as static image, because its text should change based on progress isn't it ??
So lets create a method that returns thumb image based on UISlider progress :)
Step 3
Create a IBOutlet of UISlider and set the images you have created to slider :) preferably in ViewDidLoad.
Step 4 :
Create a IBAction for your slider, and write
Final Output
EDIT
Not really sure how many noticed it, but if you have seen the o/p carefully you can see that on setting minimum track image makes the UISlider sides square!!!!
How to make Slider edges round ??
Its because the UIImage that we created using the code was returning the square image, on the other hand if we had semi sphere (semi circle) image with curve on left side slider would have shown properly :)
As writing path to draw semi circle and converting that to image will take lot of time :P I am creating circular image with corner radius and exploiting
withCapInsets
to repeat only the part of the image am interested in making the image look like semi circle :DBefore we answer that lets answer another question :P
How to increase the height of slider ???
Create a subclass of your slider, and override
As you can see am returning the height of UISlider to be 10.
Now lets go back to previous question. How to make UISlider edges curve ??
modify your minColor lazy variable declaration as below :)
What am doing here ??? Create a layer of width and height 10, set corner radius to 5 which makes it a circle of radius 5 :) Thats all.
Change your code to set slider images in viewDidLoad as below :)
What are those UIEdgeInsetsMake(3, 5, 5, 4)??
I am carefully crafting only the part of the image (part which does not have any curve) and asking iOS to repeat it :) Thats all :)
How does final O/P look like then??