This file contains 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
import UIKit | |
// MARK: Image helpers | |
extension UIImage { | |
struct Constants { | |
static let defaultTraits = [UITraitCollection(userInterfaceStyle: .dark), | |
UITraitCollection(userInterfaceStyle: .light)] | |
} |
This file contains 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
combinedImages.imageAsset?.image(with: UITraitCollection(userInterfaceStyle: .light)) | |
combinedImages.imageAsset?.image(with: UITraitCollection(userInterfaceStyle: .dark)) |
This file contains 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
// Create an asset | |
let set = UIImageAsset() | |
// Define traits to be specific for the images | |
let darkTraits = UITraitCollection(traitsFrom: [UITraitCollection(userInterfaceStyle: .dark), | |
UITraitCollection(displayScale: someDarkImage.scale)]) | |
let lightTraits = UITraitCollection(traitsFrom: [UITraitCollection(userInterfaceStyle: .light), | |
UITraitCollection(displayScale: someLightImage.scale)]) | |
// Register the images alongside the traits |
This file contains 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) |
This file contains 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 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) : |
NewerOlder