生活随笔
收集整理的這篇文章主要介紹了
iOS 键盘风格详解UIKeyboardType
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
一、鍵盤風(fēng)格 ??
UIKit框架支持8種風(fēng)格鍵盤。
[java]?view plaincopy print?
typedef?enum?{?? ????UIKeyboardTypeDefault,?????????????????? ????UIKeyboardTypeASCIICapable,????????????? ????UIKeyboardTypeNumbersAndPunctuation,???? ????UIKeyboardTypeURL,?????????????????????? ????UIKeyboardTypeNumberPad,???????????????? ????UIKeyboardTypePhonePad,????????????????? ????UIKeyboardTypeNamePhonePad,????????????? ????UIKeyboardTypeEmailAddress,????????????? }?UIKeyboardType; ?
UIKeyboardTypeDefault:
UIKeyboardTypeASCIICapable:
UIKeyboardTypeNumbersAndPunctuation:
UIKeyboardTypeURL:
UIKeyboardTypeNumberPad:
UIKeyboardTypePhonePad:
UIKeyboardTypeNamePhonePad:
UIKeyboardTypeEmailAddress:
UIKeyboardTypeDecimalPad:
UIKeyboardTypeTwitter:
UIKeyboardTypeWebSearch:
UIKeyboardTypeAlphabet:
用法用例:
textView.keyboardtype =?UIKeyboardTypeNumberPad;
二、鍵盤外觀
[java]?view plaincopy print?
typedef?enum?{?? ????UIKeyboardAppearanceDefault,?????? ????UIKeyboardAppearanceAlert,???????? }?UIKeyboardAppearance;??
用法用例:
textView.keyboardAppearance=UIKeyboardAppearanceDefault;
三、回車鍵
typedef?enum?{?? ????UIReturnKeyDefault, ?//默認(rèn):灰色按鈕,標(biāo)有Return ????UIReturnKeyGo,??//標(biāo)有Go的藍(lán)色按鈕 ????UIReturnKeyGoogle, ?//標(biāo)有Google的藍(lán)色按鈕,用于搜索 ????UIReturnKeyJoin, ?//標(biāo)有Join的藍(lán)色按鈕 ????UIReturnKeyNext, ?//標(biāo)有Next的藍(lán)色按鈕 ????UIReturnKeyRoute, ?//標(biāo)有Route的藍(lán)色按鈕 ????UIReturnKeySearch, ?//標(biāo)有Search的藍(lán)色按鈕 ????UIReturnKeySend, ?//標(biāo)有Send的藍(lán)色按鈕 ????UIReturnKeyYahoo, ?//標(biāo)有Yahoo!的藍(lán)色按鈕,用于搜索 ????UIReturnKeyDone, ?//標(biāo)有Done的藍(lán)色按鈕 ????UIReturnKeyEmergencyCall, ?//緊急呼叫按鈕 }?UIReturnKeyType; ?
用法用例:
textView.returnKeyType=UIReturnKeyGo;
四、自動(dòng)大寫
[java]?view plaincopy print?
typedef?enum?{?? ????UITextAutocapitalizationTypeNone,??? ????UITextAutocapitalizationTypeWords,??? ????UITextAutocapitalizationTypeSentences,??? ????UITextAutocapitalizationTypeAllCharacters,??? }?UITextAutocapitalizationType;??
用法用例:
textField.autocapitalizationType?=?UITextAutocapitalizationTypeWords;
五、自動(dòng)更正
[java]?view plaincopy print?
typedef?enum?{?? ????UITextAutocorrectionTypeDefault,?? ????UITextAutocorrectionTypeNo,?? ????UITextAutocorrectionTypeYes,?? }?UITextAutocorrectionType;??
用法用例:
textField.autocorrectionType?=?UITextAutocorrectionTypeYes;
六、安全文本輸入
textView.secureTextEntry=YES;
開啟安全輸入主要是用于密碼或一些私人數(shù)據(jù)的輸入,此時(shí)會(huì)禁用自動(dòng)更正和自此緩存。
七、鍵盤遮住視圖
默認(rèn)情況下打開鍵盤會(huì)遮住下面的view,帶來一點(diǎn)點(diǎn)困擾,不過這不是什么大問題,我們使用點(diǎn)小小的手段就可以解決。
首先我們要知道鍵盤的高度是固定不變的,不過在iOS?5.0 以后鍵盤的高度貌似不是216了,不過不要緊,我們調(diào)整調(diào)整就是了:
| ? | iPhone | ipad |
| 豎屏(portrait) | 216 | 264 |
| 橫屏(landScape) | 140 | 352 |
我們采取的方法就是在textField(有可能是其他控件)接收到彈出鍵盤事件時(shí)把self.view整體上移216px了(我們就以iPhone豎屏為例了)。
首先我們要設(shè)置textField的代理,我們就設(shè)為當(dāng)前控制器了。
textField,delegate=self;
然后我們?cè)诋?dāng)前控制器實(shí)現(xiàn)下面三個(gè)委托方法:
-?(void)textFieldDidBeginEditing:(UITextField?*)textField?? {??? ???????NSTimeInterval?animationDuration?=?0.30f;?????? ??????CGRect?frame?=?self.view.frame;?? ??????frame.origin.y?-=216;?? ??????frame.size.height?+=216;?? ??????self.view.frame?=?frame;?? ???????[UIView?beginAnimations:@"ResizeView"?context:nil];?? ???????[UIView?setAnimationDuration:animationDuration];?? ???????self.view.frame?=?frame;?????????????????? ???????[UIView?commitAnimations];?????????????????? } ?
-?(BOOL)textFieldShouldReturn:(UITextField?*)textField??? {?? ????????NSTimeInterval?animationDuration?=?0.30f;?? ????????CGRect?frame?=?self.view.frame;?????? ????????frame.origin.y?+=216;???????? ????????frame.size.?height?-=216;????? ????????self.view.frame?=?frame;?? ?????? ????[UIView?beginAnimations:@"ResizeView"?context:nil];?? ????[UIView?setAnimationDuration:animationDuration];?? ????????self.view.frame?=?frame;?????????????????? ????????[UIView?commitAnimations];?? ????????[textField?resignFirstResponder];????? } ? ? ? ??
參考博客:
http://blog.csdn.net/iukey
總結(jié)
以上是生活随笔為你收集整理的iOS 键盘风格详解UIKeyboardType的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。