UISegmentControl 、UIStepper

UISegmentControl 、UIStepper

  • UISegmentControl
1.    UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:@[@"1",@"2",@"3",@"4"]];
2.segmentControl.frame = (CGRect){50,100,100,50};

等同于

1.    UISegmentedControl *segmentControl = [[UISegmentedControl alloc]
2. initWithFrame:CGRectMake(50, 100, 100, 50)];
3.
4. [segmentControl insertSegmentWithTitle:@"1" atIndex:0 animated:YES];
5. [segmentControl insertSegmentWithTitle:@"2" atIndex:1 animated:YES];
6. [segmentControl insertSegmentWithTitle:@"3" atIndex:2 animated:YES];
7. [segmentControl insertSegmentWithTitle:@"4" atIndex:3 animated:YES];

其监听事件是值改变事件

1.    [segmentControl addTarget:self action:@selector(valueChange:)
2. forControlEvents:UIControlEventValueChanged];
1.-(void)valueChange:(UISegmentedControl *)sender{
2.
3. UIColor *red = [UIColor redColor];
4. UIColor *green = [UIColor purpleColor];
5. UIColor *purple = [UIColor greenColor];
6. UIColor *gray = [UIColor grayColor];
7.
8. NSArray *array = @[red,green,purple,gray];
9.
10. NSInteger index = sender.selectedSegmentIndex;
11. self.view.backgroundColor = array[index];
12.}

Alt text

  • UIStepper

    • 简单了解一些属性
      1.@property(nonatomic) double value;                        // default is 0. sends UIControlEventValueChanged. clamped to min/max
      2.@property(nonatomic) double minimumValue; // default 0. must be less than maximumValue
      3.@property(nonatomic) double maximumValue; // default 100. must be greater than minimumValue
      4.@property(nonatomic) double stepValue; // default 1. must be greater than 0
      5.
 
posted @ 2016-02-22 20:44  Emerys  阅读(270)  评论(0编辑  收藏  举报