UITextField leftView点击事件无法收听

时间:2016-07-29 04:27:39

标签: ios objective-c

将UIButton添加到UITextField的leftView,但发现单击UIButton时无法侦听单击事件

代码:

UIButton *cleanButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 15, 15)];
[cleanButton setBackgroundImage:[UIImage imageNamed:@"clean_select_member"] forState:UIControlStateNormal];
[cleanButton addTarget:self action:@selector(cleanSendMessageToUser)forControlEvents:UIControlEventTouchUpInside];
self.inputTextField.leftView = cleanButton;
self.inputTextField.leftViewMode = UITextFieldViewModeUnlessEditing;

1 个答案:

答案 0 :(得分:0)

尝试以下解决方案。 15 x 15非常小,难以触摸。

虽然苹果推荐的最小触摸面积为44 x 44,但我给出了30 x 30。

  

为交互式元素提供充足的间距。尽量保持一个   所有对照的最小可点击面积为44pt x 44pt。

UIButton *cleanButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[cleanButton setBackgroundImage:[UIImage imageNamed:@"clean_select_member"] forState:UIControlStateNormal];
[cleanButton addTarget:self action:@selector(cleanSendMessageToUser)forControlEvents:UIControlEventTouchUpInside];
self.inputTextField.leftView = cleanButton;
self.inputTextField.leftViewMode = UITextFieldViewModeUnlessEditing;