【发布时间】:2014-12-25 11:17:35
【问题描述】:
CGRect frame = CGRectMake(40, 40, 200, 30);
UITextField *textField = [[UITextField alloc] initWithFrame:frame];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.textColor = [UIColor blackColor];
textField.font = [UIFont systemFontOfSize:17.0];
textField.backgroundColor = [UIColor whiteColor];
textField.autocorrectionType = UITextAutocorrectionTypeYes;
textField.keyboardType = UIKeyboardTypeDefault;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
UIButton *but= [UIButton buttonWithType:UIButtonTypeRoundedRect];
[but addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[but setFrame:CGRectMake(80, 80, 215, 40)];
[but setTitle:@"Login" forState:UIControlStateNormal];
[but setExclusiveTouch:YES];
[view addSubview:but];
[view addSubview:textField];
[view addSubview:label];
我在单击按钮时创建了文本字段和按钮,我想在 buttonClicked 函数中获取文本字段文本
-(void) buttonClicked:(UIButton*)sender
{
// I want to get textfield text right here
}
【问题讨论】:
-
使用标签是不错的选择。为两者分配标签,然后根据标签获取值。
标签: ios objective-c xcode