-8
A
回答
0
做這樣的...
- 添加
UIImageView
爲左側圖標圖像,需要設定圖像和背景顏色 - 添加
UITextField
的ImageView的旁邊,設置邊框樣式「沒有邊框樣式' - 設置所需的背景顏色
- D Ø相同的密碼字段也,而對於眼睛圖標視圖看看這個https://github.com/Sahilberi/ImageTextField
0
添加的UITextField
添加子視圖爲ImageView的
集的字母UITextField
下面的示例代碼爲:
func addTextField() {
let txtUserName = UITextField(frame: CGRect(x: 30, y: 70, width: 320, height: 45))
let txtPassword = UITextField(frame: CGRect(x: 30, y: 140, width: 320, height: 45))
txtUserName.backgroundColor = UIColor.black
txtPassword.backgroundColor = UIColor.black
txtUserName.alpha = 0.35
txtPassword.alpha = 0.35
let imgUser = UIImageView(frame: CGRect(x: 5, y: 5, width: 35, height: 35))
let imgKey = UIImageView(frame: CGRect(x: 5, y: 5, width: 35, height: 35))
let imgEye = UIImageView(frame: CGRect(x: txtPassword.frame.size.width - 40, y: 5, width: 35, height: 35))
imgUser.image = UIImage(named: "user")
imgKey.image = UIImage(named: "key")
imgEye.image = UIImage(named: "eye")
txtUserName.addSubview(imgUser)
txtPassword.addSubview(imgKey)
txtPassword.addSubview(imgEye)
view.addSubview(txtUserName)
view.addSubview(txtPassword)
}
0
進口的UIKit
類的ViewController:UIViewController的{
@IBOutlet weak var txtpassword: UITextField!
@IBOutlet weak var txtUserName: UITextField!
@IBOutlet weak var txtView: UITextView! //your textView
override func viewDidLoad() {
super.viewDidLoad()
//navigationBarColor()
setTextFieldSpace(textField :txtUserName)
setTextFieldSpace(textField :txtpassword)
//textField border
txtpassword.borderStyle = .none
txtUserName.borderStyle = .none
}
//MARK: - Button Action
// password show hide
@IBAction func btnShowPasswordClick(_ sender: UIButton) {
if txtpassword.isSecureTextEntry{
txtpassword.isSecureTextEntry = false
}else{
txtpassword.isSecureTextEntry = true
}
}
//for set space in left side of textField
func setTextFieldSpace(textField :UITextField){
let lblSpace = UILabel()
lblSpace.frame = CGRect.init(x: 0, y: 0, width: 5, height: 5)
lblSpace.backgroundColor = .clear
textField.leftView = lblSpace
textField.leftViewMode = .always
textField.contentVerticalAlignment = .center
}
}
//檢查出了這一點把
相關問題
- 1. 自定義UITextField
- 2. 自定義UITextField
- 3. 在Swift中添加自定義輸入視圖到UITextField
- 4. 在Swift中使用自定義樣式創建UITextField擴展
- 5. 自定義UITextField/UIButton
- 6. 在自定義UITableViewCell中訪問UITextField
- 7. 在UITextField中顯示自定義圖釋
- 8. 自定義UITextField不顯示
- 9. 如何自定義UITextField
- 10. 自定義UISearchbar的UITextfield - iOS
- 11. uitextfield的自定義邊框
- 12. 設置自定義的UITextField
- 13. 如何自定義UITextField?
- 14. iOS UITextField自定義鍵盤
- 15. 創建自定義IBDesignable UITextField
- 16. 如何自定義UITextField?
- 17. 從自定義的uitableview單元格獲取uitextfield數據 - Swift
- 18. iOS 9 - 自定義UITextField使它成爲標籤字段(Swift 2)
- 19. 在UITextField中禁用「定義」
- 20. Swift中的自定義NSmenuitem
- 21. uitextfield中的自定義笑臉
- 22. 自定義UITableViewCell中的UITextField不可見
- 23. Swift自定義tableViewCell
- 24. 自定義Swift NSNumberFormatterStyle
- 25. 自定義UITextField自動完成
- 26. 如何在Swift中自定義UISlider值
- 27. 在swift中發送自定義HTTP頭
- 28. 在DDMathParser中定義自定義函數(Swift)
- 29. 在Swift中爲自定義類型定義顯式轉換
- 30. 如何在Swift中定義自定義的UIGestureRecognizer?
什麼是你的問題? –
@Anil你想定製UITextField或UITextView。 –
檢查這個答案 https://stackoverflow.com/questions/27903500/swift-add-icon-image-in-uitextfield – Arun