首頁  >  文章  >  Java  >  textfield是什麼意思啊

textfield是什麼意思啊

anonymity
anonymity原創
2019-05-06 15:07:5416169瀏覽

textfield的意思是“文字框;文字域;文字欄位;文字區;文字欄位”,它是java Swing桌面應用程式中的一個文字方塊元件,能夠實現文字的輸入和輸出,textfield有許多功能方法可以使用,豐富組件。

textfield是什麼意思啊

textfield有許多功能方法,這裡介紹一部分:

初始化textfield並設定位置及大小

UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)];

設定邊框樣式,只有設定了才會顯示邊框樣式

text.borderStyle = UITextBorderStyleRoundedRect;
typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle;

設定輸入框的背景顏色,此時設定為白色如果使用了自訂的背景圖片邊框會被忽略掉

text.backgroundColor = [UIColor whiteColor];

設定背景

text.background = [UIImage imageNamed:@"dd.png"];

設定背景

text.disabledBackground = [UIImage imageNamed:@"cc.png"];

當輸入框沒有內容時,水印提示提示內容為password

#
text.placeholder = @"password";

設定輸入框內容的字體樣式和大小

text.font = [UIFont fontWithName:@"Arial" size:20.0f];

設定字體顏色

text.textColor = [UIColor redColor];

輸入框中是否有個叉號,何時顯示,用於一次刪除輸入框中的內容

text.clearButtonMode = UITextFieldViewModeAlways;
typedef enum {UITextFieldViewModeNever, 
重不出现UITextFieldViewModeWhileEditing, 
编辑时出现UITextFieldViewModeUnlessEditing, 
除了编辑外都出现UITextFieldViewModeAlways 
一直出现} UITextFieldViewMode;

輸入框中一開始就有的文字

text.text = @"一开始就在输入框的文字";

每輸入一個字元就變成點用語密碼輸入

text.secureTextEntry = YES;

是否糾錯

text.autocorrectionType = UITextAutocorrectionTypeNo;
typedef enum {UITextAutocorrectionTypeDefault, 
默认UITextAutocorrectionTypeNo, 
不自动纠错UITextAutocorrectionTypeYes, 
自动纠错} UITextAutocorrectionType;

再次編輯就清除

text.clearsOnBeginEditing = YES;

內容對齊方式

text.textAlignment = UITextAlignmentLeft;

內容的垂直對齊方式UITextField繼承自UIControl,此類中有一個屬性contentVerticalAlignment

text.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;

設定為YES時文字會自動縮小以適應文字視窗大小.預設是保持原來大小,讓長文本滾動

textFied.adjustsFontSizeToFitWidth = YES;

設定自動縮小顯示的最小字體大小

text.minimumFontSize = 20;

設定鍵盤的樣式

text.keyboardType = UIKeyboardTypeNumberPad;
typedef enum {UIKeyboardTypeDefault, 
默认键盘,支持所有字符UIKeyboardTypeASCIICapable, 
支持ASCII的默认键盘UIKeyboardTypeNumbersAndPunctuation, 
标准电话键盘,支持+*#字符UIKeyboardTypeURL, 
URL键盘,支持.com按钮 只支持URL字符UIKeyboardTypeNumberPad, 
数字键盘UIKeyboardTypePhonePad, 
电话键盘UIKeyboardTypeNamePhonePad, 
电话键盘,也支持输入人名UIKeyboardTypeEmailAddress, 
用于输入电子 邮件地址的键盘UIKeyboardTypeDecimalPad, 
数字键盘 有数字和小数点UIKeyboardTypeTwitter, 
优化的键盘,方便输入@、#字符UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable,} UIKeyboardType;

首字母是否大寫

text.autocapitalizationType = UITextAutocapitalizationTypeNone;
typedef enum {UITextAutocapitalizationTypeNone, 
不自动大写UITextAutocapitalizationTypeWords, 
单词首字母大写UITextAutocapitalizationTypeSentences, 
句子的首字母大写UITextAutocapitalizationTypeAllCharacters, 
所有字母都大写} UITextAutocapitalizationType;

return鍵變成什麼鍵

text.returnKeyType =UIReturnKeyDone;
typedef enum {
UIReturnKeyDefault, 默认 灰色按钮,标有
ReturnUIReturnKeyGo, 标有Go的蓝色按钮UIReturnKeyGoogle, 标有Google的蓝色按钮,
用语搜索UIReturnKeyJoin, 
标有Join的蓝色按钮UIReturnKeyNext, 
标有Next的蓝色按钮UIReturnKeyRoute, 
标有Route的蓝色按钮UIReturnKeySearch, 
标有Search的蓝色按钮UIReturnKeySend, 
标有Send的蓝色按钮UIReturnKeyYahoo, 
标有Yahoo的蓝色按钮UIReturnKeyYahoo, 
标有Yahoo的蓝色按钮UIReturnKeyEmergencyCall, 
紧急呼叫按钮} UIReturnKeyType;

鍵盤外觀

textView.keyboardAppearance=UIKeyboardAppearanceDefault;
typedef enum 
{UIKeyboardAppearanceDefault, 
默认外观,浅灰色UIKeyboardAppearanceAlert, 深灰 石墨色
} UIReturnKeyType;

設定代理程式用於實作協定

text.delegate = self;

把textfield加到視圖中

[self.window addSubview:text];

最右側加圖片是以下程式碼左側類似

UIImageView *image=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"right.png"]];
text.rightView=image;
text.rightViewMode = UITextFieldViewModeAlways;

以上是textfield是什麼意思啊的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn