您好,登錄后才能下訂單哦!
UITextField 是UIControl的子類,UIControl又是UIView的子類,所以也是一個(gè)視圖,只不過比UIView多了兩個(gè)功能:(1)文字顯示(2)文本編輯
創(chuàng)建對(duì)象
UITextField * field = [[UITextField alloc]initWithFrame:CGRectMake(50, 50, 220, 30)];
配置屬性
field.backgroundColor = [UIColor whiteColor];
設(shè)置 邊框樣式
UITextBorderStyleNone,
UITextBorderStyleLine, 邊框
UITextBorderStyleBezel,
UITextBorderStyleRoundedRect 圓角
field.borderStyle = UITextBorderStyleRoundedRect;
設(shè)置輸入框默顯示(提示文字)的文字,但是不做為文本內(nèi)容的一部分
field.placeholder = @"請(qǐng)輸入用戶名";
設(shè)置開始顯示的文字
field.text = @"string";
設(shè)置文本顏色
field.textColor = [UIColor redColor];
對(duì)齊方式
field.textAlignment = NSTextAlignmentCenter;
文本字體
field.font = [UIFont fontWithName:@"Thonburi-Bold" size:20];
是否輸入框是否可編輯
field.enabled = YES;
開始時(shí)清空輸入框
field.clearsOnBeginEditing = YES;
是否文字以圓點(diǎn)格式顯示 (設(shè)置密碼模式)
field.secureTextEntry = YES;
設(shè)置彈出鍵盤的樣式
field.keyboardType = UIKeyboardTypeNumberPad;
鍵盤右下角的顯示的樣式
field.returnKeyType = UIReturnKeyGo;
代理
代理使用步驟:
1.設(shè)置代理
field.delegate = self;
2.服從協(xié)議
UITextFieldDelegate
3.實(shí)現(xiàn)協(xié)議中的方法
(BOOL)textFieldShouldReturn:(UITextField *)textField
自定義輸入視圖
UIView * v1 = [[UIView alloc]initWithFrame:CGRectMake(200, 0, 568, 100)];
v1.backgroundColor = [UIColor redColor];
field.inputView = v1;
輸入視圖上方的輔助視圖
field.inputAccessoryView = v1;
3.添加到父視圖
[_View addSubview:field];
4.釋放所有權(quán)
[field release];
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。