swift5.0 UITextfield

//1.創(chuàng)建

lettextfield =UITextField(frame:CGRect(x:50,y:100,width:200,height:40))

textfield.borderStyle= .none

self.view.addSubview(textfield)

//2.設置placeHolder

textfield.placeholder="請輸入密碼"

//3.文字超過文本框長度,自動縮小字體,且設置最小字體

textfield.adjustsFontSizeToFitWidth=true

textfield.minimumFontSize=14

//4.對齊方式

textfield.textAlignment= .center

//5.設置背景圖片

textfield.borderStyle= .none

textfield.background=UIImage(named:"backImg")

//6.右側的 X 關閉按鈕

textfield.clearButtonMode= .always

//7.設置鍵盤類型

textfield.keyboardType= .numberPad

//8.第一響應者

textfield.becomeFirstResponder()

textfield.resignFirstResponder()

//9.設置代理

textfield.delegate=self;

//10.綁定事件

textfield.addTarget(self, action:#selector(textfieldAction), for: .editingChanged)

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容