This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let font = UIFont(name: "Cochin", size: 16)! | |
let scaledFont = UIFontMetrics(forTextStyle: .body).scaledFont(for: font) | |
label.font = scaledFont | |
label.adjustsFontForContentSizeCategory = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WeightAdheringLabel: UILabel { | |
private var originalFont: UIFont? | |
override var font: UIFont! { | |
set { | |
self.originalFont = newValue | |
if traitCollection.legibilityWeight == .bold { | |
super.font = newValue.fontDescriptor.withSymbolicTraits(.traitBold).map { UIFont(descriptor: $0, size: newValue.pointSize) } ?? newValue | |
} else { | |
super.font = newValue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let backgroundColor = UIColor { | |
$0.userInterfaceStyle == .dark ? | |
UIColor(red: 10.0 / 255, green: 40.0 / 255, blue: 58.0 / 255, alpha: 1) : | |
UIColor(red: 183.0 / 255, green: 228.0 / 255, blue: 255.0 / 255, alpha: 1) | |
} | |
// Or in short: | |
let borderColour = UIColor { | |
$0.userInterfaceStyle == .dark ? | |
UIColor(red: 197.0 / 255, green: 197.0 / 255, blue: 197.0 / 255, alpha: 1) : |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIImage { | |
static func buttonBackground(color: UIColor, | |
borderColor: UIColor, | |
borderWidth: CGFloat, | |
cornerRadius: CGFloat) -> UIImage { | |
let width = max(2, cornerRadius * 2) | |
let size = CGSize(width: width, height: width) | |
return UIGraphicsImageRenderer(size: size).image { context in | |
color.setFill() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let someImage = UIImage.buttonBackground(color: backgroundColor, | |
borderColor: borderColour, | |
borderWidth: 2, | |
cornerRadius: 8) |