答案 0 :(得分:3)
比降低alpha值(可能导致其背后的其他事情出现)更好的解决方案是降低颜色的饱和度。
这是UIColor
扩展程序,它获取颜色的HSB,降低饱和度,并返回具有相同alpha的新颜色:
extension UIColor {
func softer() -> UIColor {
var h: CGFloat = 0
var s: CGFloat = 0
var b: CGFloat = 0
var a: CGFloat = 0
if self.getHue(&h, saturation: &s, brightness: &b, alpha: &a) {
// Change the 0.5 to suit your needs
return UIColor(hue: h, saturation: s * 0.5, brightness: b, alpha: a)
} else {
return self
}
}
}
// Examples:
let orange = UIColor.orange
let softOrange = orange.softer()
let brown = UIColor(red: 0.4392, green: 0.2510, blue: 0.1882, alpha: 1.0)
let softBrown = brown.softer()
答案 1 :(得分:1)
let color = UIColor.red //Your uicolor
let softColor = color.withAlphaComponent(0.5) //0<->1.0