两个输入框和一个按钮
_TextFiled = [[UITextField alloc]init];
_TextFiled.frame = CGRectMake(0, 100, 320, 50);
_TextFiled.textColor = [UIColor redColor];
_TextFiled.borderStyle = UITextBorderStyleRoundedRect;
_TextFiled.font = [UIFont boldSystemFontOfSize:20];
_TextFiled.delegate = self;
_TextFiled.tag = 1000;
[self.view addSubview:_TextFiled];
_TextFiled1 = [[UITextField alloc]init];
_TextFiled1.frame = CGRectMake(0, 300, 320, 50);
_TextFiled1.textColor = [UIColor redColor];
_TextFiled1.borderStyle = UITextBorderStyleRoundedRect;
_TextFiled1.font = [UIFont boldSystemFontOfSize:20];
_TextFiled1.delegate = self;
_TextFiled1.secureTextEntry = YES;
_TextFiled1.tag = 2000;
[self.view addSubview:_TextFiled1];
_button = [UIButton buttonWithType:UIButtonTypeCustom];
_button.frame = CGRectMake(320 / 2, 360, 100, 50);
UIImage * image_button = [UIImage imageNamed:@"9.gif"];
[_button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
[_button setImage:image_button forState:UIControlStateNormal];
[_button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.view addSubview:_button];
传值的方法
-(void)buttonAction{
//正向传值
UITextField * textField1 = (UITextField *)[self.view viewWithTag:1000];
UITextField * textField2 = (UITextField *)[self.view viewWithTag:2000];
ViewController_text * text = [[ViewController_text alloc]init];
text.text1 = textField1.text;
text.text2 = textField2.text;
//切换到下一界面
[self presentViewController:text animated:YES completion:nil];
}
在下一个界面中得到值:
UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10, 200, 310, 50)];
label.textAlignment = NSTextAlignmentLeft;
//从上一个界面传下来的值
label.text = [NSString stringWithFormat:@"Text1:%@ ----- Text2:%@", _text1,_text2];
label.textColor = [UIColor redColor];
[label setFont:[UIFont boldSystemFontOfSize:20]];
label.backgroundColor = [UIColor grayColor];
[self.view addSubview:label];