ios 11, swift 5.10
// UIKit:
self.backgroundColor = UIColor(hexString: "#4B0082")
// swiftUI:
Color(hexString: "#3498dbff")
.alpha
is a sugar for colorWithAlphaComponent
, internally it does the exact same thing, think of it as a
lipstick for your implementation.
let colorWithAlpha = myColor.alpha(0.75)
You can easily create gradient layers using the gradient()
method on arrays with UIColor
.
As an extra bonus, you can also add a transform closure if you want to modify the CAGradientLayer
.
let gradient = [UIColor.blackColor(), UIColor.orangeColor()].gradient()
let secondGradient = [UIColor.blackColor(), UIColor.orangeColor()].gradient { gradient in
gradient.locations = [0.25, 1.0]
return gradient
}
let image = UIImage(named: "My Image")
let (background, primary, secondary, detail) = image.colors()
保留两位小数
let a = 28.3213123
let b: String = a.twoDecimalPlacesStr()
url
let str = "https://github.com/"
let url: URL? = str.onlineUrl()
let name = .appDisplayName
let version = .appVersion
// 屏幕宽度
let width = screenW
// 屏幕高度
let height = screenH
https://github.com/zenangst/Hue https://github.com/Ekhoo/Device https://github.com/yannickl/DynamicColor
- universalverlay存在 BUG,视图出现时不能马上部署 overlay