Reputation: 5020
How can I acheive this in iOS UISegmentedControl (Objective-C)
I want to show rounded selection for selected segment control.
Any Help would be really appreciated.
Upvotes: 0
Views: 191
Reputation: 3960
UISegmentedControl has a section for customization.
Summary as follows: All you have to do is provide divider images for different state combinations. That means you need to provide 3 images in all for following states:
Code as follows:
Objective-C
// Image between two unselected segments.
[mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
// Image between segment selected on the left and unselected on the right.
[mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateSelected
rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
// Image between segment selected on the right and unselected on the right.
[mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateNormal
rightSegmentState:UIControlStateSelected barMetrics:barMetrics];
Swift
// Image between two unselected segments.
mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Normal,
rightSegmentState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)
// Image between segment selected on the left and unselected on the right.
mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Selected,
rightSegmentState: UIControlState.Normal, barMetrics: UIBarMetrics.Default)
// Image between segment selected on the right and unselected on the left.
mySegmentedControl.setDividerImage(myImage, forLeftSegmentState: UIControlState.Normal,
rightSegmentState: UIControlState.Selected, barMetrics: UIBarMetrics.Default)
Here is a post that explains how to achieve this.
If you see the linked post those are 3 images. Attaching the screenshot for reference:
Upvotes: 1