UILabel* label = [[UILabel alloc]initWithFrame:CGRectMake(10, 70, 60, 30)];
label.text = @"最小值";
[self.view addSubview:label];
UITextField* Txt1 = [[UITextField alloc]initWithFrame:CGRectMake(80, 70, 200, 30)];
Txt1.backgroundColor = [UIColor grayColor];
Txt1.tag = 2;
[self.view addSubview:Txt1];
UILabel* label1 = [[UILabel alloc]initWithFrame:CGRectMake(10, 120, 60, 30)];
label1.text = @"最大值";
[self.view addSubview:label1];
UITextField* Txt2 = [[UITextField alloc]initWithFrame:CGRectMake(80, 120, 200, 30)];
Txt2.backgroundColor = [UIColor grayColor];
Txt2.tag = 4;
[self.view addSubview:Txt2];
UILabel* label3 = [[UILabel alloc]initWithFrame:CGRectMake(10, 170, 200, 30)];
label3.backgroundColor = [UIColor grayColor];
label3.tag = 5;
[self.view addSubview:label3];
UIStepper* step = [[UIStepper alloc]initWithFrame:CGRectMake(10, 30, 0, 0)];
[step addTarget:self action:@selector(stepAction:) forControlEvents:UIControlEventValueChanged];
step.tag = 6;
[self.view addSubview:step];
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
[self.view addGestureRecognizer:tap];
调用方法:
UITextField* Txt1 = [self.view viewWithTag:2];
UITextField* Txt2 = [self.view viewWithTag:4];
UILabel* label3 = [self.view viewWithTag:5];
UIStepper* step = [self.view viewWithTag:6];
NSString* str = [NSString stringWithFormat:@"%f",step.value];
label3.text = str;
[Txt1 resignFirstResponder];
[Txt2 resignFirstResponder];