|
class StyledButton: UIButton { |
|
|
|
... |
|
|
|
func applyStyles() { |
|
|
|
// Apply regular style |
|
self.backgroundColor = .clear |
|
self.titleLabel?.font = Theme.fontButtonText |
|
self.tintColor = Theme.colorShadowLight.cgColor |
|
|
|
// Apply different styles |
|
for style in self.styles { |
|
|
|
// Sizes |
|
|
|
if style == .large { |
|
self.contentEdgeInsets = UIEdgeInsets(top: 16, left: 16, bottom: 16, right: 16) |
|
self.titleLabel?.font = Theme.fontButtonTextLarge |
|
self.layer.cornerRadius = 8 |
|
} |
|
|
|
if style == .wide { |
|
self.contentEdgeInsets.left = self.contentEdgeInsets.top * 2 |
|
self.contentEdgeInsets.right = self.contentEdgeInsets.top * 2 |
|
} |
|
|
|
if style == .tag { |
|
self.contentEdgeInsets = UIEdgeInsets(top: 4, left: 8, bottom: 4, right: 8) |
|
self.titleLabel?.font = Theme.fontTag |
|
self.setTitle(self.titleLabel?.text?.uppercased(), for: .normal) |
|
self.backgroundColor = Theme.colorBackgroundMuted |
|
self.layer.borderWidth = 0 |
|
} |
|
|
|
// Background |
|
|
|
if style == .primary { |
|
self.backgroundColor = Theme.colorPrimary |
|
self.tintColor = Theme.colorPrimaryContrast |
|
self.layer.borderWidth = 0 |
|
} |
|
|
|
if style == .secondary { |
|
self.backgroundColor = Theme.colorSecondary |
|
self.tintColor = Theme.colorSecondaryContrast |
|
self.layer.borderWidth = 0 |
|
} |
|
|
|
// Tint |
|
|
|
if style == .tintPrimary { |
|
self.tintColor = Theme.colorPrimary |
|
} |
|
|
|
if style == .tintSecondary { |
|
self.tintColor = Theme.colorSecondary |
|
} |
|
|
|
... |
|
|
|
} |
|
} |
|
} |