mirror of
https://github.com/SideStore/SideStore.git
synced 2026-02-09 06:43:25 +01:00
Adds PillButton.style to switch between pill and custom styles
`pill` style enforces minimum size + content insets, while `custom` doesn’t.
This commit is contained in:
@@ -14,7 +14,16 @@ extension PillButton
|
||||
static let contentInsets = NSDirectionalEdgeInsets(top: 7, leading: 13, bottom: 7, trailing: 13)
|
||||
}
|
||||
|
||||
final class PillButton: UIButton
|
||||
extension PillButton
|
||||
{
|
||||
enum Style
|
||||
{
|
||||
case pill
|
||||
case custom
|
||||
}
|
||||
}
|
||||
|
||||
class PillButton: UIButton
|
||||
{
|
||||
override var accessibilityValue: String? {
|
||||
get {
|
||||
@@ -55,6 +64,18 @@ final class PillButton: UIButton
|
||||
}
|
||||
}
|
||||
|
||||
var style: Style = .pill {
|
||||
didSet {
|
||||
if self.style == .custom
|
||||
{
|
||||
// Reset insets for custom style.
|
||||
self.contentEdgeInsets = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
|
||||
}
|
||||
|
||||
self.update()
|
||||
}
|
||||
}
|
||||
|
||||
private let progressView = UIProgressView(progressViewStyle: .default)
|
||||
|
||||
private lazy var displayLink: CADisplayLink = {
|
||||
@@ -106,8 +127,6 @@ final class PillButton: UIButton
|
||||
self.layer.masksToBounds = true
|
||||
self.accessibilityTraits.formUnion([.updatesFrequently, .button])
|
||||
|
||||
self.contentEdgeInsets = UIEdgeInsets(top: Self.contentInsets.top, left: Self.contentInsets.leading, bottom: Self.contentInsets.bottom, right: Self.contentInsets.trailing)
|
||||
|
||||
self.activityIndicatorView.style = .medium
|
||||
self.activityIndicatorView.color = .white
|
||||
self.activityIndicatorView.isUserInteractionEnabled = false
|
||||
@@ -144,8 +163,16 @@ final class PillButton: UIButton
|
||||
override func sizeThatFits(_ size: CGSize) -> CGSize
|
||||
{
|
||||
var size = super.sizeThatFits(size)
|
||||
size.width = max(size.width, PillButton.minimumSize.width)
|
||||
size.height = max(size.height, PillButton.minimumSize.height)
|
||||
|
||||
switch self.style
|
||||
{
|
||||
case .pill:
|
||||
// Enforce minimum size for pill style.
|
||||
size.width = max(size.width, PillButton.minimumSize.width)
|
||||
size.height = max(size.height, PillButton.minimumSize.height)
|
||||
|
||||
case .custom: break
|
||||
}
|
||||
|
||||
return size
|
||||
}
|
||||
@@ -170,6 +197,13 @@ private extension PillButton
|
||||
|
||||
// Update font after init because the original titleLabel is replaced.
|
||||
self.titleLabel?.font = UIFont.boldSystemFont(ofSize: 14)
|
||||
|
||||
switch self.style
|
||||
{
|
||||
case .custom: break // Don't update insets in case client has updated them.
|
||||
case .pill:
|
||||
self.contentEdgeInsets = UIEdgeInsets(top: Self.contentInsets.top, left: Self.contentInsets.leading, bottom: Self.contentInsets.bottom, right: Self.contentInsets.trailing)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func updateCountdown()
|
||||
|
||||
Reference in New Issue
Block a user