我在屏幕上有两个文本字段,但只有第二个文本字段没有接收到触摸事件。我检查了背景颜色并已经setDelegate到self.First textfield工作正常。我已经以编程方式创建了文本字段。这是我的代码:
txtMsg = [[UITextField alloc] init];
txtMsg.delegate = self;
txtMsg.placeholder = @"Type your message here..";
txtMsg.frame = CGRectMake(10, 190, 300, 40);
txtMsg.textColor = [UIColor blackColor];
txtMsg.layer.borderColor = [UIColor lightGrayColor].CGColor;
txtMsg.layer.borderWidth = 1.0f;
txtMsg.backgroundColor = [UIColor blueColor];
txtMsg.autocapitalizationType = UITextAutocapitalizationTypeNone;
txtMsg.autocorrectionType = UITextAutocorrectionTypeNo;
txtMsg.font = [UIFont systemFontOfSize:16];
[txtMsg setBorderStyle:UITextBorderStyleLine];
[self.view addSubview:txtMsg];
任何想法有什么不对?
答案 0 :(得分:0)
尝试添加:
yourTextField.userInteractionEnabled = YES;