I have a UISegmentedControl with 2 items.
Is there a way to make the left item a bit larger than the right item?
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:symbol,@"+", nil]];
[segmentedControl addTarget:self action:@selector(segmentedControlChanged:)forControlEvents:UIControlEventValueChanged];
[segmentedControl setWidth:45 forSegmentAtIndex:0];
[segmentedControl setWidth:20 forSegmentAtIndex:1];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(0,0,300,30);
segmentedControl.momentary = NO;
[segmentedControl setSelectedSegmentIndex:0];
self.navigationItem.titleView = segmentedControl;
Doesn't work.
yes you can do this:-
[*yoursegmentcontrolobjectname* setWidth:45 forSegmentAtIndex:0];
[*yoursegmentcontrolobjectname* setWidth:15 forSegmentAtIndex:1];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:symbol,@"+", nil]];
[segmentedControl addTarget:self action:@selector(segmentedControlChanged:)forControlEvents:UIControlEventValueChanged];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(0,0,300,30);
segmentedControl.momentary = NO;
[segmentedControl setSelectedSegmentIndex:0];
self.navigationItem.titleView = segmentedControl;
add these two lines now then it will work
[segmentedControl setWidth:45 forSegmentAtIndex:0];
[segmentedControl setWidth:20 forSegmentAtIndex:1];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With