日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

iOS开发之自定义键盘(数字,字母类型等随意切换)

發布時間:2024/3/13 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS开发之自定义键盘(数字,字母类型等随意切换) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

項目開發很多時候用系統給的鍵盤不是很滿足自身實際需求,那就自定義一個吧:

方法其實很簡單,重新定義一個view,繼承UItextfield,把UI設計好的需求鍵盤加入新的otherKeyboardView,然后執行代碼:

?self.inputView =self.otherKeyBoardView;

??[selfreloadInputViews];


具體效果如下:


自己封裝了一個PassTextField類,直接調用就ok:

- (void)viewDidLoad {

? ? [super viewDidLoad];

?? ?

? ? //自定義鍵盤調用

? ? PassTextFild *searchTextField =[[PassTextFild alloc]initWithFrame:CGRectMake(20,50, 280, 28)];

? ? searchTextField.borderStyle =UITextBorderStyleRoundedRect;

? ? searchTextField.placeholder =@"請輸入代碼或拼音首字母";

? ? searchTextField.font =[UIFont systemFontOfSize:13];

? ? searchTextField.contentVerticalAlignment =UIControlContentVerticalAlignmentCenter;

? ? searchTextField.autocorrectionType =UITextAutocorrectionTypeNo;

? ? searchTextField.returnKeyType = UIReturnKeyDone;

? ? searchTextField.keyboardType =UIKeyboardTypeDefault;

? ? searchTextField.clearButtonMode = UITextFieldViewModeAlways;

? ? searchTextField.text =@"";

? ? [self.view addSubview:searchTextField];

? ? [searchTextField becomeFirstResponder];

}


主要功能代碼如下:

if (pressButtonCapital.selected)

? ? {

? ? ? ? addString =[addString uppercaseString];

? ? }

? ? NSMutableString* mutableString = [[NSMutableStringalloc] initWithFormat:@"%@%@",self.text, addString];

? ? self.text = mutableString;

? ? [selfsearchAllTextField];


//切換到123鍵盤

-(void)changeNumberKeyBoard

{

? ? self.inputView =keyBoardView;

? ? [selfreloadInputViews];

}

//空格

-(void)addNullAction

{

? ? NSMutableString* mutableString = [[NSMutableStringalloc] initWithFormat:@"%@ ",self.text];

? ? self.text = mutableString;

? ? [selfsearchAllTextField];

}


//大小寫切換

-(void)pressCapitalAction:(UIButton *)button

{

? ? if (button.selected){

? ? ? ? button.selected =NO;

? ? ? ? bacDaXieImage.image =[UIImageimageNamed:@"da_.png"];

? ? }else{

? ? ? ? button.selected =YES;

? ? ? ? bacDaXieImage.image =[UIImageimageNamed:@"da.png"];

? ? }

}



好吧,廢話不多說了,具體dema直接下載:https://github.com/Deng0512/SelfKeyBoard點擊打開鏈接


總結

以上是生活随笔為你收集整理的iOS开发之自定义键盘(数字,字母类型等随意切换)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。