I have two input fields in my view, loginEmailInput
and loginPasswordInput
.
I'm trying to change the border color. My code in ViewController.swift
looks like so:
import UIKit class ViewController: UIViewController, UITextFieldDelegate { @IBOutlet weak var loginPasswordInput: UITextField! @IBOutlet weak var loginEmailInput: UITextField! let borderColor : UIColor = UIColor(red:0.39, green:0.76, blue:0.37, alpha:1) loginEmailInput.layer.borderColor = borderColor loginPasswordInput.layer.borderColor = borderColor override func viewDidLoad() { super.viewDidLoad() //etc....
However, both these lines show an error:
loginEmailInput.layer.borderColor = borderColor loginPasswordInput.layer.borderColor = borderColor
The error is:
Can't assign value of type UIColor to type CGColor
How do I solve this issue?
For a CALayer, use, as an example:
UIColor.blue.cgColor
In general, layers/ CALayers
use CG (Core Graphics) colors. While for something like background of the view, you can use something like view.backgroundColor = .blue
. UIColor is part of UIKit FrameWork (NSObject), CG is part of Core Graphic (CF/ Core Foundation Library)
Note: for very old versions of Swift (Swift 1 and 2), you would have use:
UIColor.blueColor().CGColor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With