步进器&分栏控制器

 1 @synthesize stepper = _stepper;
 2 @synthesize segContol = _segContol;
 3 
 4 - (void)viewDidLoad {
 5     [super viewDidLoad];
 6 
 7     _stepper = [[UIStepper alloc]init];
 8 
 9     _stepper.frame = CGRectMake(100, 100, 80, 40);
10     
11     _stepper.maximumValue = 100;
12     
13     _stepper.minimumValue = 0;
14     
15     //当前值
16     _stepper.value = 0;
17     //步进值
18     _stepper.stepValue = 10;
19     
20     //是否可以重复响应事件.按住键盘试一试就知道效果了
21     _stepper.autorepeat = YES;
22     
23     //是否将步进结果通过“事件函数”响应出来。yes需要,no不需要
24     _stepper.continuous = YES;
25     
26     [_stepper addTarget:self action:@selector(stepChange) forControlEvents:UIControlEventValueChanged];
27     
28     [self.view addSubview:_stepper];
29     
30     _segContol = [[UISegmentedControl alloc]init];
31     
32     //宽度可变,高度不可变
33     _segContol.frame = CGRectMake(100, 300, 280, 40);
34     
35     [_segContol insertSegmentWithTitle:@"0元" atIndex:0 animated: NO];
36     
37     [_segContol insertSegmentWithTitle:@"5元" atIndex:1 animated:NO ];
38     
39     //选择当前默认索引
40     _segContol.selectedSegmentIndex = 0;
41     
42     [_segContol addTarget:self action:@selector(segChanged) forControlEvents:
43      UIControlEventValueChanged];
44     
45     [self.view addSubview:_segContol];
46     
47 }
48 
49 -(void) segChanged
50 {
51     NSLog(@"select id is %ld",(long)_segContol.selectedSegmentIndex );
52 }
53 
54 
55 
56 
57 
58 -(void) stepChange
59 {
60     NSLog(@"Step changed value=%f",_stepper.value);
61 }

 

 

 1 @interface ViewController : UIViewController
 2 {
 3     //定义步进器
 4     UIStepper* _stepper;
 5     UISegmentedControl* _segControl;
 6     
 7 }
 8 
 9 //属性定义
10 @property(retain,nonatomic) UIStepper* stepper;
11 
12 @property(retain,nonatomic) UISegmentedControl* segContol;

 

posted @ 2017-09-25 14:22  vector11248  阅读(196)  评论(0编辑  收藏  举报