UIColor
public extension UIColor
UIColor extension.
-
Helper method to instantiate a
UIColorobject any number of ways. E.g.With integer literals:
UIColor(0xF00) UIColor(0xFF0000) UIColor(0xFF0000FF)Or string literals:
UIColor("f00") UIColor("FF0000") UIColor("rgb(255, 0, 0)") UIColor("rgba(255, 0, 0, 0.15)")Or (preferably), if you want to be a bit more explicit:
UIColor(.HEX(0xFF0000)) UIColor(.RGB(255, 0, 0)) UIColor(.RGBA(255, 0, 0, 0.5))If a provided value is invalid, the color will be white with an alpha value of 0.
Declaration
Swift
convenience init(_ color: ColorRepresentation)Parameters
color -
Undocumented
Declaration
Swift
convenience init(from string: String) -
Returns a
UIColorwith each color component ofselflightened byratio.Declaration
Swift
func lighten(byRatio ratio: CGFloat) -> UIColor -
Returns a
UIColorwith each color component ofselfdarkened byratio.Declaration
Swift
func darken(byRatio ratio: CGFloat) -> UIColor -
A bool that indicates whether the color is dark.
Note
Formula for brightness derived from W3C Techniques For Accessibility Evaluation And Repair Tools, and formula for alpha-blending attributed to StackOverflow.Declaration
Swift
var isDark: Bool { get }
View on GitHub
UIColor Extension Reference