29,027
社区成员
发帖
与我相关
我的任务
分享
UISegmentedControl *SegmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
@"开始",
@"暂停", nil]];
[SegmentedControl addTarget:self action:@selector(segmentAction:)
forControlEvents:UIControlEventValueChanged];
SegmentedControl.frame = CGRectMake(0, 0, 80, 30);
SegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
SegmentedControl.momentary = YES;
SegmentedControl.tintColor = [UIColor colorWithHue:0.6 saturation:0.33 brightness:0.69 alpha:0];
//defaultTintColor = [segmentedControl.tintColor retain]; // keep track of this for later
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc]
initWithCustomView:SegmentedControl];
self.navigationItem.rightBarButtonItem = segmentBarItem;
[/quote]
我测试了一下 在 viewDidLoad 方法中添加后 完全没有效果UISegmentedControl *SegmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
@"开始",
@"暂停", nil]];
[SegmentedControl addTarget:self action:@selector(segmentAction:)
forControlEvents:UIControlEventValueChanged];
SegmentedControl.frame = CGRectMake(0, 0, 80, 30);
SegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
SegmentedControl.momentary = YES;
SegmentedControl.tintColor = [UIColor colorWithHue:0.6 saturation:0.33 brightness:0.69 alpha:0];
//defaultTintColor = [segmentedControl.tintColor retain]; // keep track of this for later
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc]
initWithCustomView:SegmentedControl];
self.navigationItem.rightBarButtonItem = segmentBarItem;
[/quote]
这个是要放在 viewDidLoad 方法中么?(PS:不好意思 手残了 点了个板砖。。)UISegmentedControl *SegmentedControl = [[UISegmentedControl alloc] initWithItems:
[NSArray arrayWithObjects:
@"开始",
@"暂停", nil]];
[SegmentedControl addTarget:self action:@selector(segmentAction:)
forControlEvents:UIControlEventValueChanged];
SegmentedControl.frame = CGRectMake(0, 0, 80, 30);
SegmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
SegmentedControl.momentary = YES;
SegmentedControl.tintColor = [UIColor colorWithHue:0.6 saturation:0.33 brightness:0.69 alpha:0];
//defaultTintColor = [segmentedControl.tintColor retain]; // keep track of this for later
UIBarButtonItem *segmentBarItem = [[UIBarButtonItem alloc]
initWithCustomView:SegmentedControl];
self.navigationItem.rightBarButtonItem = segmentBarItem;