iphone的软键盘 及 软键盘增加一个 done 按钮 iphone 软键盘

本文介绍如何在iOS应用中定制软键盘的行为与外观,包括设置清除按钮模式、键盘类型、呈现风格、自动大写类型、自动纠正选项、返回键类型等,并提供了一个增加自定义按键的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

iphone 软键盘

分类:iPhone开发 1098人阅读 评论(0) 收藏 举报

当文本输入时, 文本框有几中选择用于辅助输入:

textField.clearButtonMode=UITextFieldViewModeWhileEditing;

Java代码
  1. typedefenum{
  2. UITextFieldViewModeNever,//clearbutton永远不出现
  3. UITextFieldViewModeWhileEditing,//编辑的时候出现
  4. UITextFieldViewModeUnlessEditing,//未编辑的时候出现
  5. UITextFieldViewModeAlways//永远都出现
  6. }UITextFieldViewMode;

弹出的键盘类型也可以辅助快速输入:

textField.keyboardType=UIKeyboardTypeAlphabet;

Java代码
  1. typedefenum{
  2. UIKeyboardTypeDefault,//Defaulttypeforthecurrentinputmethod.
  3. UIKeyboardTypeASCIICapable,//DisplaysakeyboardwhichcanenterASCIIcharacters,non-ASCIIkeyboardsremainactive
  4. UIKeyboardTypeNumbersAndPunctuation,//Numbersandassortedpunctuation.
  5. UIKeyboardTypeURL,//AtypeoptimizedforURLentry(shows./.comprominently).
  6. UIKeyboardTypeNumberPad,//Anumberpad(0-9).SuitableforPINentry.
  7. UIKeyboardTypePhonePad,//Aphonepad(1-9,*,0,#,withlettersunderthenumbers).
  8. UIKeyboardTypeNamePhonePad,//Atypeoptimizedforenteringaperson'snameorphonenumber.
  9. UIKeyboardTypeEmailAddress,//Atypeoptimizedformultipleemailaddressentry(showsspace@.prominently).
  10. UIKeyboardTypeAlphabet=UIKeyboardTypeASCIICapable,//Deprecated
  11. }UIKeyboardType;

键盘的呈现风格:

textField..keyboardAppearance=UIKeyboardAppearanceAlert;

Java代码
  1. typedefenum{
  2. UIKeyboardAppearanceDefault,//Defaultapperanceforthecurrentinputmethod.
  3. UIKeyboardAppearanceAlert,//Appearancesuitableforusein"alert"scenarios.
  4. }UIKeyboardAppearance;

键盘对输入字母的控制:

textField.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;

Java代码
  1. typedefenum{
  2. UITextAutocapitalizationTypeNone,//什么也不做
  3. UITextAutocapitalizationTypeWords,//单词首字母大写
  4. UITextAutocapitalizationTypeSentences,//句子首字母大些
  5. UITextAutocapitalizationTypeAllCharacters,//所有字母大些
  6. }UITextAutocapitalizationType;

键盘对输入字母自动纠正

textField.autocorrectionType=UITextAutocorrectionTypeYes;

Java代码
  1. typedefenum{
  2. UITextAutocorrectionTypeDefault,
  3. UITextAutocorrectionTypeNo,
  4. UITextAutocorrectionTypeYes,
  5. }UITextAutocorrectionType;

确认键的类型

textField.returnKeyType=UIReturnKeyDone;

Java代码
  1. typedefenum{
  2. UIReturnKeyDefault,
  3. UIReturnKeyGo,
  4. UIReturnKeyGoogle,
  5. UIReturnKeyJoin,
  6. UIReturnKeyNext,
  7. UIReturnKeyRoute,
  8. UIReturnKeySearch,
  9. UIReturnKeySend,
  10. UIReturnKeyYahoo,
  11. UIReturnKeyDone,
  12. UIReturnKeyEmergencyCall,
  13. }UIReturnKeyType;

最后一个技巧,也是网上收集,键盘透明以及增加一个按键的应用:

[[NSNotificationCenter defaultCenter] addObserver:self

Java代码
  1. selector:@selector(keyboardWillShow:)
  2. name:UIKeyboardWillShowNotification
  3. object:nil];
  4. --------------------
  5. -(void)keyboardWillShow:(NSNotification*)note{
  6. //createcustombutton
  7. UIButton*doneButton=[UIButtonbuttonWithType:UIButtonTypeCustom];
  8. doneButton.frame=CGRectMake(0,163,106,53);
  9. doneButton.adjustsImageWhenHighlighted=NO;
  10. [doneButtonsetImage:[UIImageimageNamed:@"DoneUp.png"]forState:UIControlStateNormal];
  11. [doneButtonsetImage:[UIImageimageNamed:@"DoneDown.png"]forState:UIControlStateHighlighted];
  12. [doneButtonaddTarget:selfaction:@selector(doneButton:)forControlEvents:UIControlEventTouchUpInside];
  13. //locatekeyboardview
  14. UIWindow*tempWindow=[[[UIApplicationsharedApplication]windows]objectAtIndex:1];
  15. UIView*keyboard;
  16. for(inti=0;i<[tempWindow.subviewscount];i++){
  17. keyboard=[tempWindow.subviewsobjectAtIndex:i];
  18. //keyboardviewfound;addthecustombuttontoit
  19. if([[keyboarddescription]hasPrefix:@"<UIKeyboard"]==YES)
  20. [keyboardaddSubview:doneButton];
  21. }
  22. }

当文本输入时, 文本框有几中选择用于辅助输入:

textField.clearButtonMode=UITextFieldViewModeWhileEditing;

Java代码
  1. typedefenum{
  2. UITextFieldViewModeNever,//clearbutton永远不出现
  3. UITextFieldViewModeWhileEditing,//编辑的时候出现
  4. UITextFieldViewModeUnlessEditing,//未编辑的时候出现
  5. UITextFieldViewModeAlways//永远都出现
  6. }UITextFieldViewMode;

弹出的键盘类型也可以辅助快速输入:

textField.keyboardType=UIKeyboardTypeAlphabet;

Java代码
  1. typedefenum{
  2. UIKeyboardTypeDefault,//Defaulttypeforthecurrentinputmethod.
  3. UIKeyboardTypeASCIICapable,//DisplaysakeyboardwhichcanenterASCIIcharacters,non-ASCIIkeyboardsremainactive
  4. UIKeyboardTypeNumbersAndPunctuation,//Numbersandassortedpunctuation.
  5. UIKeyboardTypeURL,//AtypeoptimizedforURLentry(shows./.comprominently).
  6. UIKeyboardTypeNumberPad,//Anumberpad(0-9).SuitableforPINentry.
  7. UIKeyboardTypePhonePad,//Aphonepad(1-9,*,0,#,withlettersunderthenumbers).
  8. UIKeyboardTypeNamePhonePad,//Atypeoptimizedforenteringaperson'snameorphonenumber.
  9. UIKeyboardTypeEmailAddress,//Atypeoptimizedformultipleemailaddressentry(showsspace@.prominently).
  10. UIKeyboardTypeAlphabet=UIKeyboardTypeASCIICapable,//Deprecated
  11. }UIKeyboardType;

键盘的呈现风格:

textField..keyboardAppearance=UIKeyboardAppearanceAlert;

Java代码
  1. typedefenum{
  2. UIKeyboardAppearanceDefault,//Defaultapperanceforthecurrentinputmethod.
  3. UIKeyboardAppearanceAlert,//Appearancesuitableforusein"alert"scenarios.
  4. }UIKeyboardAppearance;

键盘对输入字母的控制:

textField.autocapitalizationType=UITextAutocapitalizationTypeAllCharacters;

Java代码
  1. typedefenum{
  2. UITextAutocapitalizationTypeNone,//什么也不做
  3. UITextAutocapitalizationTypeWords,//单词首字母大写
  4. UITextAutocapitalizationTypeSentences,//句子首字母大些
  5. UITextAutocapitalizationTypeAllCharacters,//所有字母大些
  6. }UITextAutocapitalizationType;

键盘对输入字母自动纠正

textField.autocorrectionType=UITextAutocorrectionTypeYes;

Java代码
  1. typedefenum{
  2. UITextAutocorrectionTypeDefault,
  3. UITextAutocorrectionTypeNo,
  4. UITextAutocorrectionTypeYes,
  5. }UITextAutocorrectionType;

确认键的类型

textField.returnKeyType=UIReturnKeyDone;

Java代码
  1. typedefenum{
  2. UIReturnKeyDefault,
  3. UIReturnKeyGo,
  4. UIReturnKeyGoogle,
  5. UIReturnKeyJoin,
  6. UIReturnKeyNext,
  7. UIReturnKeyRoute,
  8. UIReturnKeySearch,
  9. UIReturnKeySend,
  10. UIReturnKeyYahoo,
  11. UIReturnKeyDone,
  12. UIReturnKeyEmergencyCall,
  13. }UIReturnKeyType;

最后一个技巧,也是网上收集,键盘透明以及增加一个按键的应用:

[[NSNotificationCenter defaultCenter] addObserver:self

Java代码
  1. selector:@selector(keyboardWillShow:)
  2. name:UIKeyboardWillShowNotification
  3. object:nil];
  4. --------------------
  5. -(void)keyboardWillShow:(NSNotification*)note{
  6. //createcustombutton
  7. UIButton*doneButton=[UIButtonbuttonWithType:UIButtonTypeCustom];
  8. doneButton.frame=CGRectMake(0,163,106,53);
  9. doneButton.adjustsImageWhenHighlighted=NO;
  10. [doneButtonsetImage:[UIImageimageNamed:@"DoneUp.png"]forState:UIControlStateNormal];
  11. [doneButtonsetImage:[UIImageimageNamed:@"DoneDown.png"]forState:UIControlStateHighlighted];
  12. [doneButtonaddTarget:selfaction:@selector(doneButton:)forControlEvents:UIControlEventTouchUpInside];
  13. //locatekeyboardview
  14. UIWindow*tempWindow=[[[UIApplicationsharedApplication]windows]objectAtIndex:1];
  15. UIView*keyboard;
  16. for(inti=0;i<[tempWindow.subviewscount];i++){
  17. keyboard=[tempWindow.subviewsobjectAtIndex:i];
  18. //keyboardviewfound;addthecustombuttontoit
  19. if([[keyboarddescription]hasPrefix:@"<UIKeyboard"]==YES)
  20. [keyboardaddSubview:doneButton];
  21. }
  22. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值