标签:style blog color io 使用 ar for sp div
问题:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.view.backgroundColor = [UIColor whiteColor]; NSArray *segments = [[NSArray alloc]initWithObjects: @"iPhone", @"iPad", @"iPod", @"iMac", nil]; _mySegmentControl = [[UISegmentedControl alloc]initWithItems:segments]; _mySegmentControl.center = self.view.center; [self.view addSubview:_mySegmentControl]; }
[_mySegmentControl addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
//segment选项变化时调用方法 - (void)segmentChanged:(UISegmentedControl *)paramSender{ if ([paramSender isEqual:_mySegmentControl]) { NSInteger selectedSegmentIndex = [paramSender selectedSegmentIndex]; NSString *selectedSegmentText = [paramSender titleForSegmentAtIndex:selectedSegmentIndex]; NSLog(@"Segment %ld with %@ text is selected", (long)selectedSegmentIndex,selectedSegmentText); } }
_mySegmentControl.momentary = YES;
NSArray *segments = [[NSArray alloc] initWithObjects: @"iPhone", [UIImage imageNamed:@"iPad.png"], @"iPod", @"iMac", nil]; self.mySegmentedControl = [[UISegmentedControl alloc] initWithItems:segments];
UI: UISegmentedControl 做简单选项分组及其自定义
标签:style blog color io 使用 ar for sp div
原文地址:http://www.cnblogs.com/safiri/p/4015744.html