Last active
October 4, 2017 01:49
-
-
Save rsaenzi/1a3a7d62d2432917f0922b7d60d288ec to your computer and use it in GitHub Desktop.
To add inspectable properties to control the border of a view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIView+Border.swift | |
// | |
// Created by Rigoberto Sáenz Imbacuán (https://www.linkedin.com/in/rsaenzi/) | |
// Copyright © 2017. All rights reserved. | |
// | |
import UIKit | |
@IBDesignable | |
extension UIView { | |
@IBInspectable | |
var cornerRadius: CGFloat { | |
get { | |
return layer.cornerRadius | |
} | |
set { | |
layer.cornerRadius = newValue | |
layer.masksToBounds = newValue > 0 | |
clipsToBounds = newValue > 0 | |
} | |
} | |
@IBInspectable | |
var borderWidth: CGFloat { | |
set { | |
layer.borderWidth = newValue | |
} | |
get { | |
return layer.borderWidth | |
} | |
} | |
@IBInspectable | |
var borderColor: UIColor? { | |
set { | |
layer.borderColor = newValue?.cgColor | |
} | |
get { | |
if let color = layer.borderColor { | |
return UIColor(cgColor: color) | |
} else { | |
return nil | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment