生活随笔
收集整理的這篇文章主要介紹了
iOS 键盘风格详解UIKeyboardType
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、鍵盤風格 ??
UIKit框架支持8種風格鍵盤。
[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, ?//默認:灰色按鈕,標有Return ????UIReturnKeyGo,??//標有Go的藍色按鈕 ????UIReturnKeyGoogle, ?//標有Google的藍色按鈕,用于搜索 ????UIReturnKeyJoin, ?//標有Join的藍色按鈕 ????UIReturnKeyNext, ?//標有Next的藍色按鈕 ????UIReturnKeyRoute, ?//標有Route的藍色按鈕 ????UIReturnKeySearch, ?//標有Search的藍色按鈕 ????UIReturnKeySend, ?//標有Send的藍色按鈕 ????UIReturnKeyYahoo, ?//標有Yahoo!的藍色按鈕,用于搜索 ????UIReturnKeyDone, ?//標有Done的藍色按鈕 ????UIReturnKeyEmergencyCall, ?//緊急呼叫按鈕 }?UIReturnKeyType; ?
用法用例:
textView.returnKeyType=UIReturnKeyGo;
四、自動大寫
[java]?view plaincopy print?
typedef?enum?{?? ????UITextAutocapitalizationTypeNone,??? ????UITextAutocapitalizationTypeWords,??? ????UITextAutocapitalizationTypeSentences,??? ????UITextAutocapitalizationTypeAllCharacters,??? }?UITextAutocapitalizationType;??
用法用例:
textField.autocapitalizationType?=?UITextAutocapitalizationTypeWords;
五、自動更正
[java]?view plaincopy print?
typedef?enum?{?? ????UITextAutocorrectionTypeDefault,?? ????UITextAutocorrectionTypeNo,?? ????UITextAutocorrectionTypeYes,?? }?UITextAutocorrectionType;??
用法用例:
textField.autocorrectionType?=?UITextAutocorrectionTypeYes;
六、安全文本輸入
textView.secureTextEntry=YES;
開啟安全輸入主要是用于密碼或一些私人數據的輸入,此時會禁用自動更正和自此緩存。
七、鍵盤遮住視圖
默認情況下打開鍵盤會遮住下面的view,帶來一點點困擾,不過這不是什么大問題,我們使用點小小的手段就可以解決。
首先我們要知道鍵盤的高度是固定不變的,不過在iOS?5.0 以后鍵盤的高度貌似不是216了,不過不要緊,我們調整調整就是了:
| ? | iPhone | ipad |
| 豎屏(portrait) | 216 | 264 |
| 橫屏(landScape) | 140 | 352 |
我們采取的方法就是在textField(有可能是其他控件)接收到彈出鍵盤事件時把self.view整體上移216px了(我們就以iPhone豎屏為例了)。
首先我們要設置textField的代理,我們就設為當前控制器了。
textField,delegate=self;
然后我們在當前控制器實現下面三個委托方法:
-?(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
總結
以上是生活随笔為你收集整理的iOS 键盘风格详解UIKeyboardType的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。