UITextField 和 UITextView
如图修改键盘
开源地址,可点击查看
UIReturnKeyDefault
UIReturnKeyGo
UIReturnKeyGoogle
UIReturnKeyJoin
UIReturnKeyNext
UIReturnKeyRoute
UIReturnKeySearch
UIReturnKeySend
加粗样式
UIReturnKeyDone
UIReturnKeyEmergencyCall
UIReturnKeyContinue
UITextView *textView = [[UITextView alloc] init];textView.returnKeyType = UIReturnKeyDone;UITextField *textField= [[UITextField alloc] init];textView.returnKeyType = UIReturnKeyDone;
对回车符事件进行监听
实现 UITextViewDelegate代理里面响
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
实现 UITextFieldDelegate代理里面响
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
这个函数的最后一个参数text代表你每次输入的的那个字,所以:- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{if ([text isEqualToString:@"\n"]){//判断输入的字是否是回车,即按下return//[textView endEditing:YES];//在这里做你响应return键的代码return NO; //这里返回NO,就代表return键值失效,即页面上按下return,不会出现换行,如果为yes,则输入页面会换行}return YES;}
typedef NS_ENUM(NSInteger, UIReturnKeyType) {UIReturnKeyDefault,UIReturnKeyGo,UIReturnKeyGoogle,UIReturnKeyJoin,UIReturnKeyNext,UIReturnKeyRoute,UIReturnKeySearch,UIReturnKeySend,UIReturnKeyYahoo,UIReturnKeyDone,UIReturnKeyEmergencyCall,UIReturnKeyContinue NS_ENUM_AVAILABLE_IOS(9_0),};
查看完整代码