How can i add a SwiftUI Color? Normally on UIKit you can create your own Colors but in SwiftUI con Color struct it's not easy like UIColor, but it's not complicate.
extension UIColor {
UIColor(red: 219/255, green: 175/255, blue: 15/255, alpha: 1.0)
}
You can create a color set like this one (which is called "black")
And after in your code just create an extension of Color:
import SwiftUI
extension Color {
static let customBlack = Color("black")
}
And when you will use this customBlack, if you turn you app in darkMode it will use the dark appearance that you have set in your colorset.
You can use it like this in your code:
Image(systemName: "person.crop.circle")
.foregroundColor(.customBlack)
You can create your own SwiftUI Color with Color extension in a new file.swift
import SwiftUI
extension Color {
public static var myCustomColor: Color {
return Color(UIColor(red: 219/255, green: 175/255, blue: 15/255, alpha: 1.0))
}
}
Add New color set file in Assets.xcassets and colors with name.
Code: Color("ColorName")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With