RandomGeek RandomGeek - 1 month ago 8
iOS Question

Custom Color with cgColor

It might be the stupidest question you saw all day but i couldn't find a solution. i have a rounded image view with borders and i want the borders to be the the same blue as the default tint color in Xcode so if you could help that would be great . and sorry for the noonish question ;)

Now i have this:

self.imageView.layer.borderColor = UIColor.gray.cgColor

and i need to change


to be the same blue as the default tint color without causing a crash or an error ... how can it be done?

thanks for your help.

Answer Source

just create the new color with blue color properties and apply to imageView

let color = UIColor(colorLiteralRed: 0, green: 122/255, blue: 1, alpha: 1.0)
self.imageView.layer.borderColor = color.cgColor

alertnatively you can use tintColor property of imageView like

imageView.layer.borderColor = imageView.tintColor.cgColor