forked from matvdg/AppleMusic-UIButton-UITextField
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppleMusicButton.swift
79 lines (64 loc) · 1.76 KB
/
AppleMusicButton.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// AppleMusicButton.swift
// Mathieu Vandeginste
//
// Created by Mathieu Vandeginste on 18/10/2016.
// Copyright © 2016 Mathieu Vandeginste. All rights reserved.
//
import UIKit
@IBDesignable public class AppleMusicButton: UIButton {
@IBInspectable var shadowColor: UIColor = UIColor.clear {
didSet {
setNeedsLayout()
}
}
@IBInspectable var shadowX: CGFloat = 0 {
didSet {
setNeedsLayout()
}
}
@IBInspectable var shadowY: CGFloat = 0 {
didSet {
setNeedsLayout()
}
}
@IBInspectable var shadowBlur: CGFloat = 0 {
didSet {
setNeedsLayout()
}
}
@IBInspectable var cornerRadius: CGFloat = 2.0 {
didSet {
setNeedsLayout()
}
}
@IBInspectable var appleMusicRadius: Bool = true {
didSet {
setNeedsLayout()
}
}
@IBInspectable var borderColor: UIColor = UIColor.white {
didSet {
layer.borderColor = borderColor.cgColor
}
}
@IBInspectable var borderWidth: CGFloat = 2.0 {
didSet {
layer.borderWidth = borderWidth
}
}
override public func layoutSubviews() {
super.layoutSubviews()
if self.appleMusicRadius {
self.layer.cornerRadius = self.bounds.height / 2
} else {
layer.cornerRadius = cornerRadius
}
self.titleLabel?.adjustsFontSizeToFitWidth = true
clipsToBounds = false
layer.shadowColor = shadowColor.cgColor
layer.shadowOffset = CGSize(width: shadowX, height: shadowY)
layer.shadowRadius = shadowBlur
layer.shadowOpacity = 1
}
}