ios - Make 2 segments the size of 1 in UISegmentedControl -
i have uisegmentedcontrol
3 segments created in storyboard
. want programmatically add segment, , make middle 2 segments size of 1 segment. here image illustrate:
in storyboard
:
what want achieve programmatically:
this 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 desirable effects. widths weird. how can widths second image above?
half of 1/3 not 1/4. 1/6.
you want set three of segments , leave last 1 set automatically fill remainder.
don't run code - if do, segmented control may not have achieved final frame yet,
segmentwidth
wrong.
Comments
Post a Comment