iOS 从UIColor调整颜色的亮度
示例
下面的代码示例将为您提供该颜色的调整版本,其中较高的百分比将变亮,而较低的百分比将变暗。
目标C
+ (UIColor *)adjustedColorForColor:(UIColor *)c : (double)percent
{
if (percent < 0) percent = 0;
CGFloat r, g, b, a;
if ([c getRed:&r green:&g blue:&b alpha:&a])
return [UIColor colorWithRed:MAX(r * percent, 0.0)
green:MAX(g * percent, 0.0)
blue:MAX(b * percent, 0.0)
alpha:a];
return nil;
}迅速
func adjustedColorForColor( c: UIColor, var percent: CGFloat) -> UIColor {
if percent < 0 {
percent = 0
}
var r,g,b,a: CGFloat
r = 0.0
g = 0.0
b = 0.0
a = 0.0
if c.getRed(&r, green: &g, blue: &b, alpha: &a) {
return UIColor(red: max(r * percent, 0.0), green: max(g * percent, 0.0), blue: max(b * percent, 0.0), alpha: a)
}
return UIColor()
}
热门推荐
10 2026猪年祝福语简短语
11 餐前仪式祝福语简短
12 舰长生日祝福语简短
13 女性生日祝福语简短优美
14 新年祝福语简短创意兄弟
15 道教生日祝福语简短大全
16 上级买车祝福语大全简短
17 海鲜送礼祝福语简短大全
18 贺卡祝福语宝宝男孩简短