【发布时间】:2014-08-08 09:58:17
【问题描述】:
我有一些想法,但是对于第一次创建带有“if 条件”的 UITextField 来说当然不行。 我怎样才能做到这一点? 我可以设置“如果 UITextField 已经存在”这样的条件吗???
这是我的代码:
-(void)tapDetected:(UIGestureRecognizer*)recognizer{
NSLog(@"tap detected.");
CGPoint point = [recognizer locationInView:self.truckImageView];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, point.y, 300, 40)];
[textField becomeFirstResponder];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.font = [UIFont systemFontOfSize:24];
textField.placeholder = @"enter text";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.delegate = self;
if (textField.text && textField.text.length > 0)
{
[self.view addSubview:textField];
// textField.alpha = 0.5;
[textField setBackgroundColor:[UIColor clearColor]];
}
else
{
NSLog(@"textField is already created.");
}
}
【问题讨论】:
标签: ios objective-c uitextfield uitapgesturerecognizer