iOS学习(UI)知识点整理一、UI小组件1、UISegmentedControl 分段选择器 实例代码 1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 //分段选择器 4 //在iOS6里,每个段的宽度会根据字 ...
iOS学习(UI)知识点整理
一、UI小组件1、UISegmentedControl 分段选择器 实例代码
1 - (void)viewDidLoad { 2 [super viewDidLoad]; 3 //分段选择器 4 //在iOS6里,每个段的宽度会根据字数来决定 5 //iOS7以后,每个段的宽度相同,宽度取决于最长的字数 6 self.view.backgroundColor=[UIColor whiteColor]; 7 seg=[[UISegmentedControl alloc]initWithItems:@[@"消息",@"视频电话"]]; 8 self.navigationItem.titleView=seg; 9 //设置选中的某一个选项 10 seg.selectedSegmentIndex=1; 11 12 UIButton *button=[[UIButton alloc]init];13 button.frame=CGRectMake(80, 100, 200, 30);14 button.backgroundColor=[UIColor blackColor];15 [button setTitle:@"添加" forState:UIControlStateNormal];16 [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];17 [button addTarget:self action:@selector(touchButton:) forControlEvents:UIControlEventTouchUpInside];18 19 [self.view addSubview:button]; 20 UIButton *rmbutton=[[UIButton alloc]init];21 rmbutton.frame=CGRectMake(80, 200, 200, 30);22 rmbutton.backgroundColor=[UIColor blackColor];23 [rmbutton setTitle:@"移除" forState:UIControlStateNormal];24 [rmbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];25 [rmbutton addTarget:self action:@selector(touchRmButton:) forControlEvents:UIControlEventTouchUpInside]; 26 [self.view addSubview:rmbutton]; 27 //给seg添加点击事件的监听28 [seg addTarget:self action:@selector(changeView:) forControlEvents:UIControlEventValueChanged]; 29 }30 31 //插入一个图片组成的段32 -(void)touchButton:(UIButton*)button{ 33 //[seg insertSegmentWithTitle:button.titleLabel.text atIndex:2 animated:YES];34 [seg insertSegmentWithImage:[UIImage imageNamed:@"005"] atIndex:2 animated:YES];35 36 }37 //移除某一个segment38 -(void)touchRmButton:(UIButton*)button{ 39 [seg removeSegmentAtIndex:1 animated:YES]; 40 } 41 //按钮点击事件42 -(void)changeView:(UISegmentedControl*)mseg{43 NSLog(@"%li",mseg.selectedSegmentIndex); 44 }
原标题:iOS阶段学习第34天笔记(UI小组件 UISegment
关键词:IOS
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。