0

I have tried so many times to just get a simple border on an ImageView but nothing seems to work. Those are my active settings now:

Settings

But the result is still without any border.

No border

What am I missing in my settings?

halfer
  • 19,824
  • 17
  • 99
  • 186
thelearner
  • 1,440
  • 3
  • 27
  • 58

1 Answers1

2

layer.borderColor is a CGColorRef. But interface builder passes a UIColor. You have two options:

1 - Set the border color in code:

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

2 - Extend UIImageView or UIView with a borderColor property and use @IBDesignable and @IBInspectableso that property is visible in interface builder. Use this new property as a proxy to layer.borderColor.

@IBDesignable
extension UIView {
    @IBInspectable
    var borderColor: UIColor? {
        get {
            if let cgColor = self.layer.borderColor {
                return UIColor(cgColor: cgColor)
            }
            return nil
        } set {
            self.layer.borderColor = newValue?.cgColor
        }
    }
}

Related Posts:

https://stackoverflow.com/a/17993890/3814799

https://stackoverflow.com/a/35372610/3814799

Jake
  • 13,097
  • 9
  • 44
  • 73