-
Notifications
You must be signed in to change notification settings - Fork 0
/
RoundButton.swift
62 lines (45 loc) · 1.84 KB
/
RoundButton.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
//
// RoundedButton.swift
// Inaldo&Tony
//
// Created by Davide Cifariello on 13/12/17.
// Copyright © 2017 Antonio Sirica. All rights reserved.
//
import UIKit
class RoundedButton: UIButton {
let mainColor = UIColor(red:0.48, green:0.73, blue:0.84, alpha:1.0)
override func awakeFromNib() {
super.awakeFromNib()
//layer.borderWidth = 1/UIScreen.main.nativeScale
//contentEdgeInsets = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
//titleLabel?.adjustsFontForContentSizeCategory = true
}
override func layoutSubviews() {
super.layoutSubviews()
layer.cornerRadius = frame.height/4
//layer.borderColor = isEnabled ? tintColor.cgColor : UIColor.lightGray.cgColor
self.tintColor = UIColor(red:0.48, green:0.73, blue:0.84, alpha:0.0)
self.frame.size = CGSize(width: 80, height: 40)
layer.borderWidth = 1
layer.borderColor = UIColor(red:0.48, green:0.73, blue:0.84, alpha:1.0).cgColor
if self.isSelected {
self.backgroundColor = UIColor(red:0.48, green:0.73, blue:0.84, alpha:0.6)
self.titleLabel?.textColor = UIColor.black
self.layer.borderWidth = 2.5
} else {
if self.backgroundColor != mainColor {
self.backgroundColor = UIColor.black
self.titleLabel?.textColor = UIColor(red:0.48, green:0.73, blue:0.84, alpha:1.0)
} else {
self.titleLabel?.textColor = UIColor.black
}
}
}
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
}