-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathDesignableButton.swift
55 lines (45 loc) · 1.66 KB
/
DesignableButton.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// DesignableButton.swift
// Example
//
// Created by Gunter Hager on 03.06.16.
// Copyright © 2016 all about apps. All rights reserved.
//
import UIKit
import SimpleButton
@IBDesignable
class DesignableButton: SimpleButton {
/// Background color for normal state.
@IBInspectable var backgroundColorNormal: UIColor?
@IBInspectable var backgroundColorHighlight: UIColor?
@IBInspectable var titleColorNormal: UIColor?
@IBInspectable var titleColorHighlighted: UIColor?
@IBInspectable var shadow: Bool = false
@IBInspectable var shadowColor: UIColor?
@IBInspectable var shadowOffset: CGSize = CGSize.zero
@IBInspectable var shadowRadius: CGFloat = 0
@IBInspectable var shadowOpacity: Float = 0
override func configureButtonStyles() {
super.configureButtonStyles()
if let backgroundColorNormal = backgroundColorNormal {
setBackgroundColor(backgroundColorNormal, for: .normal)
}
if let backgroundColorHighlight = backgroundColorHighlight {
setBackgroundColor(backgroundColorHighlight, for: .highlighted)
}
if let titleColorNormal = titleColorNormal {
setTitleColor(titleColorNormal, for: .normal)
}
if let titleColorHighlighted = titleColorHighlighted {
setTitleColor(titleColorHighlighted, for: .highlighted)
}
if shadow {
if let shadowColor = shadowColor {
setShadowColor(shadowColor)
}
setShadowOffset(shadowOffset)
setShadowRadius(shadowRadius)
setShadowOpacity(shadowOpacity)
}
}
}