From 590fcd37afcaecac79ff0186ef28d1c89d5b3194 Mon Sep 17 00:00:00 2001 From: krugerk <4656811+krugerk@users.noreply.github.com> Date: Sat, 19 Oct 2024 22:47:15 +0200 Subject: [PATCH] Black on grey without border in light mode (#492) follow-up to #489, implementing https://github.com/beeminder/BeeSwift/pull/489#discussion_r1792894445 ### light ![light - sign in](https://github.com/user-attachments/assets/96600ddf-06a3-46c7-b8bf-78d148bb58bd) ### dark ![dark - sign in](https://github.com/user-attachments/assets/7354983e-690d-492e-a477-ab71d1f9eac8) --- BeeKit/UI/BSButton.swift | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/BeeKit/UI/BSButton.swift b/BeeKit/UI/BSButton.swift index 87d74a69f..9e6feaa33 100644 --- a/BeeKit/UI/BSButton.swift +++ b/BeeKit/UI/BSButton.swift @@ -12,15 +12,7 @@ import UIKit public class BSButton : UIButton { required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - - registerForTraitChanges( - [UITraitUserInterfaceStyle.self]) { - (self: Self, previousTraitCollection: UITraitCollection) in - self.resetStyle() - } - - self.setUp() + fatalError("init(coder:) has not been implemented; neither xib nor storyboards in use") } override init(frame: CGRect) { @@ -32,23 +24,22 @@ public class BSButton : UIButton { self.resetStyle() } - self.setUp() + self.resetStyle() } - private func setUp() { + private func resetStyle() { + self.configuration = .filled() + self.titleLabel?.font = UIFont.beeminder.defaultBoldFont + self.setTitleColor(dynamicTitleColor, for: UIControl.State()) self.tintColor = dynamicTintFillColor - self.configuration = .filled() + + self.backgroundColor = .clear - self.layer.borderColor = UIColor.Beeminder.yellow.cgColor - self.layer.borderWidth = 1 - self.layer.cornerRadius = 4 - } - - private func resetStyle() { - self.tintColor = dynamicTintFillColor - self.setTitleColor(dynamicTitleColor, for: UIControl.State()) + self.layer.borderColor = traitCollection.userInterfaceStyle == .dark ? UIColor.Beeminder.yellow.cgColor : UIColor.clear.cgColor + self.layer.borderWidth = traitCollection.userInterfaceStyle == .dark ? 1 : 0 + self.layer.cornerRadius = traitCollection.userInterfaceStyle == .dark ? 4 : 0 } private let dynamicTintFillColor = UIColor { traitCollection in