An advanced Ethereum/EVM mobile wallet
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
alpha-wallet-ios/Trust/UI/Button.swift

117 lines
2.9 KiB

// Copyright SIX DAY LLC. All rights reserved.
import Foundation
import UIKit
enum ButtonSize: Int {
case small
case normal
case large
case extraLarge
var height: CGFloat {
switch self {
case .small: return 32
case .normal: return 44
case .large: return 50
case .extraLarge: return 64
}
}
}
enum ButtonStyle: Int {
case solid
case squared
case border
case borderless
var backgroundColor: UIColor {
switch self {
case .solid, .squared: return Colors.blue
case .border, .borderless: return .white
}
}
var backgroundColorHighlighted: UIColor {
switch self {
case .solid, .squared: return Colors.blue
case .border: return Colors.blue
case .borderless: return .white
}
}
var cornerRadius: CGFloat {
switch self {
case .solid, .border: return 5
case .squared, .borderless: return 0
}
}
var font: UIFont {
switch self {
case .solid,
.squared,
.border,
.borderless:
return UIFont.systemFont(ofSize: 16, weight: UIFontWeightMedium)
}
}
var textColor: UIColor {
switch self {
case .solid, .squared: return .white
case .border, .borderless: return Colors.blue
}
}
var textColorHighlighted: UIColor {
switch self {
case .solid, .squared: return UIColor(white: 1, alpha: 0.8)
case .border: return .white
case .borderless: return Colors.blue
}
}
var borderColor: UIColor {
switch self {
case .solid, .squared, .border: return Colors.blue
case .borderless: return .clear
}
}
var borderWidth: CGFloat {
switch self {
case .solid, .squared, .borderless: return 0
case .border: return 1
}
}
}
class Button: UIButton {
init(size: ButtonSize, style: ButtonStyle) {
super.init(frame: .zero)
NSLayoutConstraint.activate([
heightAnchor.constraint(equalToConstant: size.height),
])
backgroundColor = style.backgroundColor
layer.cornerRadius = style.cornerRadius
layer.borderColor = style.borderColor.cgColor
layer.borderWidth = style.borderWidth
layer.masksToBounds = true
titleLabel?.textColor = style.textColor
titleLabel?.font = style.font
setTitleColor(style.textColor, for: .normal)
setTitleColor(style.textColorHighlighted, for: .highlighted)
setBackgroundColor(style.backgroundColorHighlighted, forState: .highlighted)
setBackgroundColor(style.backgroundColorHighlighted, forState: .selected)
contentEdgeInsets = UIEdgeInsets(top: 5, left: 10, bottom: 5, right: 10)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}