Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set a UITextField's borderColor?

Tags:

ios

swift

I am trying to set a UITextField's borderColor in iOS 8 in Swift. I tried using this code:

myTextField.layer.borderColor = UIColor( red: 0.5, green: 0.5, blue:0, alpha: 1.0 )  

I got this error:

UIColor not convertible to CGColor

like image 303
Narayan Srivathsan Avatar asked Jul 15 '14 17:07

Narayan Srivathsan


1 Answers

@coderRed gave you an Objective C answer and a Swift answer. Ignore his first Line

I broke it up into 2 statements below in Swift:

let myColor : UIColor = UIColor( red: 0.5, green: 0.5, blue:0, alpha: 1.0 ) myTextField.layer.borderColor = myColor.CGColor 

Hope this helps! Good luck with learning Swift

like image 89
weePee Avatar answered Sep 17 '22 21:09

weePee