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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

UITextField的详细使用

發布時間:2023/11/27 生活经验 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UITextField的详细使用 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

UItextField通常用于外部數據輸入,以實現人機交互。下面以一個簡單的登陸界面來講解UItextField的詳細使用。

//用來顯示“用戶名”的label

UILabel* label1 = [[UILabelalloc]?initWithFrame:CGRectMake(15,?65,?70,?30)];

? ? label1.backgroundColor?= [UIColorclearColor];

? ? label1.font?= [UIFontfontWithName:@"Helvetica-Bold"size:18];

? ? label1.text?=?@"用戶名";

? ? label1.textColor?= [UIColorwhiteColor];

? ? [view1?addSubview:label1];

? ? [label1?release];

? ?UITextField *?accountField?= [[UITextField alloc]?initWithFrame:CGRectMake(85.0f,?60.0f,?190.0f,?40.0f)];

[accountField setBorderStyle:UITextBorderStyleRoundedRect];?//外框類型

accountField.placeholder = @"用戶名";?//默認顯示的字

accountField.secureTextEntry = NO;?//是否以密碼形式顯示

accountField.autocorrectionType?=?UITextAutocorrectionTypeNo;//設置是否啟動自動提醒更正功能

accountField.autocapitalizationType?=?UITextAutocapitalizationTypeNone;

accountField.returnKeyType?=?UIReturnKeyDone; ?//鍵盤返回類型

accountField.clearButtonMode?=?UITextFieldViewModeWhileEditing;?//編輯時會出現個修改X

accountField.delegate?=?self;

accountField.keyboardType?=?UIKeyboardTypeDefault;//鍵盤顯示類型

accountField.contentVerticalAlignment?=?UIControlContentVerticalAlignmentCenter;?//設置居中輸入

accountField.scrollEnabled = YES;//是否可以拖動

accountField.autoresizingMask = UIViewAutoresizingFlexibleHeight;//自適應高度

?

? ??//用來顯示“密碼”的label

? ??UILabel* label2 = [[UILabelalloc]?initWithFrame:CGRectMake(15,?120,?70,?30)];

? ? label2.backgroundColor?= [UIColorclearColor];

? ? label2.font?= [UIFontfontWithName:@"Helvetica-Bold"size:18];

? ? label2.text?=?@"密碼";

? ? label2.textColor?= [UIColorwhiteColor];

? ? [view1?addSubview:label2];

? ? [label2?release];

? UITextField*??passwdField?= [[UITextField alloc]?initWithFrame:CGRectMake(85.0f,?115.0f,?190.0f,?40.0f)];

[passwdFieldsetBorderStyle:UITextBorderStyleRoundedRect];?//外框類型

//passwdField.placeholder = @"密碼";?//默認顯示的字

passwdField.secureTextEntry?=?YES;?//密碼類型

?

passwdField.autocorrectionType?=?UITextAutocorrectionTypeNo;? ?

passwdField.autocapitalizationType?=?UITextAutocapitalizationTypeNone;

passwdField.returnKeyType?=?UIReturnKeyDone;

passwdField.clearButtonMode?=?UITextFieldViewModeWhileEditing;?//編輯時會出現個修改X

passwdField.delegate?=?self;

?// passwdField.keyboardAppearance = UIKeyboardAppearanceDefault;

passwdField.keyboardType?=?UIKeyboardTypeNumbersAndPunctuation;

passwdField.contentVerticalAlignment?=?UIControlContentVerticalAlignmentCenter;

?

委托方法

-(void)textFieldDidBeginEditing:(UITextField?*)textField; ?

//當開始點擊textField會調用的方法 ???

?

?

-(void)textFieldDidEndEditing:(UITextField?*)textField;?

//當textField編輯結束時調用的方法

?

//按下Done按鈕的調用方法,我們讓鍵盤消失???

-(BOOL)textFieldShouldReturn:(UITextField?*)textField{ ?

?

?[textField?resignFirstResponder]; ?

?return?YES;

?

轉載于:https://www.cnblogs.com/top5/archive/2012/05/17/2506608.html

總結

以上是生活随笔為你收集整理的UITextField的详细使用的全部內容,希望文章能夠幫你解決所遇到的問題。

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