UISegmentedControl:分栏控件,常用的属性和方法是
1.tintColor:控制分栏控件的颜色风格
2.insertSegmentWithTitle(Image):插入分栏标题(图片)
UIStepper:步进器,常用来控制数字的加减,常用的属性:
1.maximumValue:步进器支持的最大值
2.minimumValue:步进器支持的最小值
3.value:步进器的当前值
4.stepValue:步进器每一步的递进值
5.continous:是否支持长按时连续触发回调函数
6.autoRepeat:是否支持长按
7.tintColor:步进器的颜色风格
- (void) createUI { int x = 10; int width = [[UIScreen mainScreen] bounds].size.width - 20; self.stepper = [[UIStepper alloc] initWithFrame:CGRectMake(x, 50, width, 50)]; //步进器的最大值 self.stepper.maximumValue = 100; //步进器的最小值 self.stepper.minimumValue = 0; //步进器单步的大小 self.stepper.stepValue = 10; //步进器的当前值 self.stepper.value = 50; //步进器长按时是否连续调用回调函数 self.stepper.continuous = YES; //步进器是否支持长按 self.stepper.autorepeat = YES; //步进器的颜色风格 self.stepper.tintColor = [UIColor redColor]; //步进器当前值发生变化时的回调 [self.stepper addTarget:self action:@selector(stepperChanged) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:self.stepper]; self.segCtrl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(x, 100, width, 40)]; //分栏控件填充数据(支持文字和图片) [self.segCtrl insertSegmentWithTitle:@"今日头条" atIndex:0 animated:NO]; [self.segCtrl insertSegmentWithTitle:@"网易新闻" atIndex:1 animated:NO]; [self.segCtrl insertSegmentWithTitle:@"新浪微博" atIndex:2 animated:NO]; //分栏控件的颜色风格 self.segCtrl.tintColor = [UIColor redColor]; //分栏控件当前选中的栏 self.segCtrl.selectedSegmentIndex = 0; //设置分栏控件选中栏发生变化时的回调 [self.segCtrl addTarget:self action:@selector(segCtrlChanged) forControlEvents:UIControlEventValueChanged]; [self.view addSubview:self.segCtrl]; }
时间: 2024-12-24 12:08:36