1

I'm trying to set runtime attributes layer.borderColor in swift (for a prototype tableview)

However, the color setting does not actually set the UIColor as pointed out in a bunch of answers. Is there a swift implementation of this:

Is it possible to set UIView border properties from interface builder?

Community
  • 1
  • 1
Onichan
  • 4,476
  • 6
  • 31
  • 60

1 Answers1

7

You need to proxy the value to set it as a CGColor. I answered the question you mentioned for Objective-C, and now here it is in swift.

extension UIView
{
    var borderColor: UIColor {
        set{ self.layer.borderColor = newValue.CGColor }
        get{ return UIColor(CGColor: self.layer.borderColor!) }
    }
}
Community
  • 1
  • 1
Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101