开发者

UISegmentControl configuration

开发者 https://www.devze.com 2023-03-14 02:49 出处:网络
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 75, 25)]; label.textAlignment = UITextAlignmentRight;
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 75, 25)];
label.textAlignment = UITextAlignmentRight;
label.tag = kLabelTag;
label.font = [UIFont boldSystemFontOfSize:14];
label.text = @"Lawn Sign";

[cell.contentView addSubview:label];
[label release];

UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:nil];
NSArray * item = [ NSArray arrayWithObjects:@"No",@"Install",@"Replace",@"Move", nil];
[segmentedControl initWithItems:item];
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.frame = CGRectMake(90, 10, 200, 30);
[segmentedControl setMomentary:YES];
[segmentedControl addTarget:self action:@selector(segmentAction:) forControlEven开发者_运维问答ts:UIControlEventValueChanged];
segmentedControl.tag = 14;

[cell.contentView addSubview:segmentedControl];
[segmentedControl release];

Here's my UISegmentedControl configuration for a cell in the tableview but when I tap on an option in the segmentedControl, it doesn't switch.


You've set the control to be momentary. Change this:

[segmentedControl setMomentary:YES];

to this:

[segmentedControl setMomentary:NO];

and the control will show its selected state.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号