Answers:
colorWithAlphaComponent:
做到了。
所以我要做的是:
self.mylabel.backgroundColor = [self.myLabel.backgroundColor colorWithAlphaComponent:0.3];
UIColor(red:0.07, green:0.44, blue:0.54, alpha:0.4)
为什么不使用 label.alpha = 0.5
?调整标签的Alpha值?
更新:如果要从旧颜色调整Alpha,请参考以下示例:
UIColor uicolor = [UIColor greenColor];
CGColorRef color = [uicolor CGColor];
int numComponents = CGColorGetNumberOfComponents(color);
UIColor newColor;
if (numComponents == 4)
{
const CGFloat *components = CGColorGetComponents(color);
CGFloat red = components[0];
CGFloat green = components[1];
CGFloat blue = components[2];
newColor = [UIColor colorWithRed: red green: green blue: blue alpha: YOURNEWALPHA];
}
UIColor
?对于标签,您可以使用.alpha
属性。