Files
SideStore/Sources/SideStoreAppKit/Components/Button.swift

58 lines
1.0 KiB
Swift
Raw Normal View History

//
// Button.swift
// AltStore
//
// Created by Riley Testut on 5/9/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import UIKit
2023-03-01 00:48:36 -05:00
final class Button: UIButton {
override var intrinsicContentSize: CGSize {
var size = super.intrinsicContentSize
size.width += 20
size.height += 10
return size
}
2023-03-01 00:48:36 -05:00
override func awakeFromNib() {
super.awakeFromNib()
2023-03-01 00:48:36 -05:00
setTitleColor(.white, for: .normal)
layer.masksToBounds = true
layer.cornerRadius = 8
update()
}
2023-03-01 00:48:36 -05:00
override func tintColorDidChange() {
super.tintColorDidChange()
2023-03-01 00:48:36 -05:00
update()
}
2023-03-01 00:48:36 -05:00
override var isHighlighted: Bool {
didSet {
self.update()
}
}
2023-03-01 00:48:36 -05:00
override var isEnabled: Bool {
didSet {
2023-03-01 00:48:36 -05:00
update()
}
}
}
2023-03-01 00:48:36 -05:00
private extension Button {
func update() {
if isEnabled {
backgroundColor = tintColor
} else {
backgroundColor = .lightGray
}
}
}