#define SCREEN_WIDHT [[UIScreen mainScreen] bounds].size.width
#define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height
#define COMMON_HEIGHT SCREEN_HEIGHT * 0.054
UISegmentedControl是这样用滴:
//设置一下要展示的数据
NSArray *controlArray = [[NSArray alloc]initWithObjects:@"1",@"2", nil];
//初始化UISegmentedControl
UISegmentedControl *control = [[UISegmentedControl alloc]initWithItems:controlArray];
control.frame = CGRectMake(10, 74, SCREEN_WIDHT-20, COMMON_HEIGHT);
//设置背景颜色
control.tintColor = [UIColor grayColor];
//设置默认选中第几个按钮,下标从0开始
control.selectedSegmentIndex = 0;
[control addTarget:self action:@selector(selector:) forControlEvents: UIControlEventValueChanged];
[self.view addSubview:control];
-(void)selector:(id)sender{
UISegmentedControl *control = (UISegmentedControl *)sender;
switch (control.selectedSegmentIndex) {
case 0:
//这里是第一个按钮
break;
case 1:
//这里是第二个按钮
break;
}
}