How to change uitextfield border when selected
If you want to highlight TextField when user starts typing, I suggest you to use UITextField
delegate method textFieldDidBeginEditing
for handling when user starts typing.
func textFieldDidBeginEditing(_ textField: UITextField) {
if textField == email {
textField.layer.borderWidth = 4
textField.layer.borderColor = // your color
} else if ...
}
you can also use textFieldDidEndEditing
delegate method for handling when user is done with typing
func textFieldDidEndEditing(_ textField: UITextField) {
textField.layer.borderWidth = // default width
textField.layer.borderColor = // default color
}
So if you want to use these methods, don't forget to set delegate
properties of your TextFields in viewDidLoad
for example
email.delegate = self
password.delegate = self
userName.delegate = self
also don't forget to implement UITextFieldDelegate
protocol
class ViewController: UIViewController, UITextFieldDelegate
How set swift 3 UITextField border color?
You also need to set border width
, because your border color is set already but your default border width is 0.0 so you can't see it.
So, set border width something like,
email.layer.borderWidth = 1.0
Update :
Your code should be like,
@IBOutlet weak var email: UITextField!
@IBOutlet weak var pass: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
let myColor = UIColor.white
email.layer.borderColor = myColor.cgColor
pass.layer.borderColor = myColor.cgColor
email.layer.borderWidth = 1.0
pass.layer.borderWidth = 1.0
}
Related Topics
My App Was Just Rejected for Using the Ad Support Framework. Which Library Is Responsible
How to Enable Back/Left Swipe Gesture in Uinavigationcontroller After Setting Leftbarbuttonitem
How to Create Negative Firebase Timestamp in Swift
Realmswift: Convert Results to Swift Array
Set Default iOS Local Notification Style for Application
How to Get the Udid in iOS 6 and iOS 7
Remove Println() for Release Version iOS Swift
Check If Optional Array Is Empty
Reading the Gps Data from the Image Returned by the Camera in iOS Iphone
Change Text Color of Items in Uiactionsheet - iOS 8
Pod Install -Bash: Pod: Command Not Found
Draw Dotted (Not Dashed!) Line, with Ibdesignable in 2017
Duplicate Symbol Error in Nsmanagedobject Subclass
Swift - Which Types to Use? Nsstring or String
iOS Simulator Games Run Very Slow (Low Fps)
Force Landscape Viewcontroller in iOS 7
Restoring Animation Where It Left Off When App Resumes from Background