[英]Conversion from UIColor with alpha component to CGColor
这段代码很好用
self.fillColor = [UIColor whiteColor].CGColor;
虽然这在我的drawRect函数中引发了异常
self.fillColor = [[UIColor whiteColor] colorWithAlphaComponent:0.2].CGColor;
的drawRect:
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, self.fillColor); //exception here
CGContextSetStrokeColorWithColor(context, self.fillColor);
CGContextFillEllipseInRect(context, rect);
CGContextStrokeEllipseInRect(context, rect);
}
怎么了
好。 看来错误是由于属性定义的方式引起的。
尝试以这种方式定义它...
@property UIColor *fillColor;
然后在drawRect中可以使用...
fillColor.CGColor
我已经做过数百次了。 Alpha值没有任何区别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.