Skip to content

Instantly share code, notes, and snippets.

@Daemon-Devarshi
Created December 17, 2016 09:09
Show Gist options
  • Save Daemon-Devarshi/7b7bdec68d60e7129a63abc46655ec4b to your computer and use it in GitHub Desktop.
Save Daemon-Devarshi/7b7bdec68d60e7129a63abc46655ec4b to your computer and use it in GitHub Desktop.
Handy code to configure a bordered view using storyboard
//
// 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