Created
November 2, 2018 01:40
-
-
Save priyans05/264c8c488e559b92fc51f8ef4f7f660e to your computer and use it in GitHub Desktop.
Extend Any UIView on storyboard with shadow, corner radius etc.
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
// | |
// ExtensionUIView.swift | |
// SimpleLoginWithFirebase | |
// | |
// Created by PRIYANS on 2/11/18. | |
// Copyright © 2018 PRIYANS. All rights reserved. | |
// | |
//TODO: Go to identity inspector after selecting button/image/label and Change the class like configurableButton/configurableImage. | |
import UIKit | |
@IBDesignable class configurableView: UIView {} | |
@IBDesignable class configurableButton: UIButton {} | |
@IBDesignable class configurableLabel: UILabel {} | |
@IBDesignable class configurableImage: UIImageView {} | |
extension UIView { | |
@IBInspectable var cornerRadius: CGFloat { | |
get { | |
return layer.cornerRadius | |
} | |
set { | |
layer.cornerRadius = newValue | |
} | |
} | |
@IBInspectable var borderWidth: CGFloat { | |
get { | |
return layer.borderWidth | |
} | |
set { | |
layer.borderWidth = newValue | |
} | |
} | |
@IBInspectable var borderColor: UIColor? { | |
get { | |
if let color = layer.borderColor { | |
return UIColor(cgColor: color) | |
} | |
return nil | |
} | |
set { | |
if let color = newValue { | |
layer.borderColor = color.cgColor | |
} else { | |
layer.borderColor = nil | |
} | |
} | |
} | |
@IBInspectable var shadowRadius: CGFloat { | |
get { | |
return layer.shadowRadius | |
} | |
set { | |
layer.shadowRadius = newValue | |
} | |
} | |
@IBInspectable var shadowOpacity: Float { | |
get { | |
return layer.shadowOpacity | |
} | |
set { | |
layer.shadowOpacity = newValue | |
} | |
} | |
@IBInspectable var shadowOffset: CGSize { | |
get { | |
return layer.shadowOffset | |
} | |
set { | |
layer.shadowOffset = newValue | |
} | |
} | |
@IBInspectable var shadowColor: UIColor? { | |
get { | |
if let color = layer.shadowColor { | |
return UIColor(cgColor: color) | |
} | |
return nil | |
} | |
set { | |
if let color = newValue { | |
layer.shadowColor = color.cgColor | |
} | |
else { | |
layer.shadowColor = nil | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment