Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // DesignableControl.swift
- //
- import UIKit
- @IBDesignable
- class DesignableControl: UIControl {
- @IBInspectable var cornerRadius: CGFloat = 0.0 {
- didSet {
- self.layer.cornerRadius = self.cornerRadius
- }
- }
- @IBInspectable var roundView: Bool = false
- @IBInspectable var borderColor: UIColor = .clear {
- didSet {
- self.layer.borderColor = self.borderColor.cgColor
- }
- }
- @IBInspectable var borderWidth: CGFloat = 0.0 {
- didSet {
- self.layer.borderWidth = self.borderWidth
- }
- }
- @IBInspectable var shadowColor: UIColor = .clear {
- didSet {
- self.layer.shadowColor = self.shadowColor.cgColor
- }
- }
- @IBInspectable var shadowOpacity: Float = 0.0 {
- didSet {
- self.layer.shadowOpacity = self.shadowOpacity
- }
- }
- @IBInspectable var shadowOffset: CGSize = .zero {
- didSet {
- self.layer.shadowOffset = self.shadowOffset
- }
- }
- @IBInspectable var shadowRadius: CGFloat = 0.0 {
- didSet {
- self.layer.shadowRadius = self.shadowRadius
- }
- }
- @IBInspectable var gradientStartColor: UIColor = .clear {
- didSet {
- if let layer = self.layer as? CAGradientLayer {
- layer.colors = [self.gradientStartColor.cgColor, self.gradientEndColor.cgColor]
- }
- }
- }
- @IBInspectable var gradientEndColor: UIColor = .clear {
- didSet {
- if let layer = self.layer as? CAGradientLayer {
- layer.colors = [self.gradientStartColor.cgColor, self.gradientEndColor.cgColor]
- }
- }
- }
- @IBInspectable var gradientStart: CGPoint = CGPoint(x: 0.0, y: 1.0) {
- didSet {
- if let layer = self.layer as? CAGradientLayer {
- layer.startPoint = self.gradientStart
- }
- }
- }
- @IBInspectable var gradientEnd: CGPoint = CGPoint(x: 1.0, y: 0.0) {
- didSet {
- if let layer = self.layer as? CAGradientLayer {
- layer.endPoint = self.gradientEnd
- }
- }
- }
- override class var layerClass: AnyClass {
- return CAGradientLayer.self
- }
- override func layoutSubviews() {
- super.layoutSubviews()
- self.layer.cornerRadius = self.roundView ? (min(self.bounds.width, self.bounds.height) / 2.0) : self.cornerRadius
- }
- override func prepareForInterfaceBuilder() {
- super.prepareForInterfaceBuilder()
- self.layer.cornerRadius = self.roundView ? (min(self.bounds.width, self.bounds.height) / 2.0) : self.cornerRadius
- }
- }
Add Comment
Please, Sign In to add comment