计步器最多最小值自己输入(OC)

时间:2022-01-13 21:55:51

计步器最多最小值自己输入(OC)

  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 加手势
[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];
//[sender setMinimumValue:[_Txt1.text doubleValue]];
//[sender setMaximumValue:[_Txt1.text doubleValue]];
NSString* str = [NSString stringWithFormat:@"%f",step.value];
label3.text = str;

[Txt1 resignFirstResponder];
[Txt2 resignFirstResponder];