Skip to content

Instantly share code, notes, and snippets.

@GonzalezAnguita
Last active February 9, 2019 12:56
Show Gist options
  • Save GonzalezAnguita/c5bc310145a1f74ee61e026852cc8f4f to your computer and use it in GitHub Desktop.
Save GonzalezAnguita/c5bc310145a1f74ee61e026852cc8f4f to your computer and use it in GitHub Desktop.
Border and corner extension for UIView - Swift 3
//
// Credits to:
// https://gist.github.com/feighter09/c502d7550e4cdb82d526157f5cf8bef1
// http://nshipster.com/ibinspectable-ibdesignable/
//
// Created by José Tomás González on 23-04-17.
// Copyright © 2017 Swipe. All rights reserved.
//
import Foundation
import UIKit
extension UIView {
@IBInspectable var borderColor: UIColor? {
get {
return layer.borderColor.map(UIColor.init)
}
set {
layer.borderColor = newValue?.cgColor
}
}
@IBInspectable var borderWidth: CGFloat {
get {
return layer.borderWidth
}
set {
layer.borderWidth = newValue
}
}
@IBInspectable var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
}
}
}
@GonzalezAnguita
Copy link
Author

README

This code adds the possibility of modifying an interface border color, width and corner radius through the Interface Builder’s inspector panel of any element that inherits from UIView.

ibinspectable-inspectable
Credits to NSHipster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment