UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 100, 30)] textField.returnKeyType = UIReturnKeySearch; //設置按鍵類型 textField.enablesReturnKeyAutomatically = YES; //這里設置為無文字就灰色不可點
在代理方法中響應
- (BOOL)textFieldShouldReturn:(UITextField *)textField { [self searchAction]; [textField resignFirstResponder]; return YES; }