Created
December 17, 2016 09:09
-
-
Save Daemon-Devarshi/7b7bdec68d60e7129a63abc46655ec4b to your computer and use it in GitHub Desktop.
Handy code to configure a bordered view using storyboard
This file contains hidden or 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
// | |
// BorderedView.swift | |
// | |
// Created by Devarshi Kulshreshtha on 17/12/16. | |
// Copyright © 2016 Devarshi. All rights reserved. | |
// | |
import UIKit | |
@IBDesignable | |
class BorderedView: UIView { | |
// properties with default values | |
@IBInspectable var borderColor: UIColor = UIColor.white { | |
didSet { | |
layer.borderColor = borderColor.cgColor | |
} | |
} | |
@IBInspectable var borderWidth: CGFloat = 1.0 { | |
didSet { | |
layer.borderWidth = borderWidth | |
} | |
} | |
@IBInspectable var cornerRadius: CGFloat = 0 { | |
didSet { | |
layer.cornerRadius = cornerRadius | |
layer.masksToBounds = cornerRadius > 0 | |
} | |
} | |
override func draw(_ rect: CGRect) { | |
layer.borderColor = borderColor.cgColor | |
layer.borderWidth = borderWidth | |
layer.cornerRadius = cornerRadius | |
layer.masksToBounds = cornerRadius > 0 | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
} | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment