Onichan
Onichan

Reputation: 4526

Set UIView BorderColor in IB for Swift

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?

Upvotes: 1

Views: 1331

Answers (1)

Peter DeWeese
Peter DeWeese

Reputation: 18343

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!) }
    }
}

Upvotes: 7

Related Questions