I have a UISegmentedControl
with 3 segments created in the storyboard
. I want to programmatically add another segment, and make the middle 2 segments the size of 1 segment. Here is an image to illustrate:
In storyboard
:
What I want to achieve programmatically:
This is what I tried:
CGFloat segmentWidth = self.segment.frame.size.width;
[self.segment insertSegmentWithTitle:@"titleName" atIndex:2 animated:NO];
[self.segment setWidth:segmentWidth / 4 forSegmentAtIndex:1];
[self.segment setWidth:segmentWidth / 4 forSegmentAtIndex:2];
[self.segment setWidth:segmentWidth / 3 forSegmentAtIndex:0];
[self.segment setWidth:segmentWidth / 3 forSegmentAtIndex:3];
It didn't give me the desirable effects. The widths were weird. How can I get the widths to be like the second image above?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…