我有2个项目的UISegmentedControl。
有没有办法使左边的项目比右边的项目大一些?
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;
不起作用
最佳答案
是的,您可以这样做:
[*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;
现在添加这两行,那么它将起作用
[segmentedControl setWidth:45 forSegmentAtIndex:0];
[segmentedControl setWidth:20 forSegmentAtIndex:1];
关于iphone - 有没有办法使UISegmentedControl按钮具有不同的大小?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7157571/