Is there a way so that you can set both image and title of
UISegmentControl simultaneously, so that image appear next to the title , just like image appear next to title in
I am trying but if I set image of Selected segment of
UISegmentControl then title disappears and if I set title of Selected segment of
UISegmentControl then Image disappears, I want to set both at a time.
Best How To :
The official documentation for
A segment can only have an image or a title; it can’t have both. There is no default image.
So, no, there is no way to do what you want using the image and title properties.
However, there are a few options to accomplish the objective in different ways.
- if you are going to use the same image for each segment, you could use the appearance methods to set the background and then use the method
-setContentOffset:forSegmentAtIndex: to move the title to the side of the background image.
- you could create an image that had both the icon and the text in it. This is less than ideal as a change to the text requires exporting of the entire asset again. But is an option.
- the least ideal would be to fake a segmented control using buttons that you write the code for to handle state changes. There may even be some open source options that do just that, so feel free to search for them.