ios中分段控件的使用

时间:2022-06-30 04:34:23
    NSArray *array=[NSArray arrayWithObjects:@"亚洲",@"欧洲",@"美国",nil];
UISegmentedControl *seg=[[UISegmentedControl alloc]initWithItems:array];
seg.frame=CGRectMake(30, 100, 300, 50);
//修改颜色
seg.tintColor=[UIColor yellowColor];
//默认选中下标
seg.selectedSegmentIndex=1;
//添加点击事件
[seg addTarget:self action:@selector(selectWitch) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:seg];