輸入文字用
TextField
功能:
UITextField提供了一個可供輸入的地方,經由螢幕點選後,提供虛擬鍵盤進行輸入

實作:

[xcode]
CGRect frame = CGRectMake(20, 100, 250, 44);
UITextField *textField = [[UITextField alloc] initWithFrame:frame];
[textField setText:@"一般文字"];
[textField setPlaceholder:@"提示文字"];
[textField setBackgroundColor:[UIColor whiteColor]];
[textField setBorderStyle:UITextBorderStyleRoundedRect];
[textField setKeyboardType:UIKeyboardTypeDefault];
[view addSubview:textField];
[/xcode]

參考:
UITextField

屬性 property:
text 顯示文字
placeholder 提示文字
textAlignment 文字對齊方法

方法 Method:
setText: 設定文字
setPlaceholder: 設定提示文字
setBorderStyle: 設定樣式
[c]
typedef enum {
UITextBorderStyleNone,
UITextBorderStyleLine,
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect
} UITextBorderStyle;
[/c]

由父類別 UIView 提供:
setBackgroundColor: 設定背景顏色

由 UITextInputTraits Protocol 提供:
setKeyboardType: 設定鍵盤樣式
[c]
typedef enum {
UIKeyboardTypeDefault,
UIKeyboardTypeASCIICapable,
UIKeyboardTypeNumbersAndPunctuation,
UIKeyboardTypeURL,
UIKeyboardTypeNumberPad,
UIKeyboardTypePhonePad,
UIKeyboardTypeNamePhonePad,
UIKeyboardTypeEmailAddress,
UIKeyboardTypeDecimalPad,
UIKeyboardTypeTwitter,
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable
} UIKeyboardType;
[/c]

廣告