【问题标题】:DrawRect keeps drawing white backgroundDrawRect 不断绘制白色背景
【发布时间】:2013-03-04 19:56:24
【问题描述】:
//inside init
_color = [UIColor orangeColor];
self.backgroundColor = [UIColor clearColor];
self.clearsContextBeforeDrawing = NO;

//inside drawRect
CGContextRef ctx = UIGraphicsGetCurrentContext();

CGContextSaveGState(ctx);
    CGContextAddEllipseInRect(ctx, rect);
    CGContextSetFillColorWithColor(ctx,
                                   _color.CGColor);
    CGContextFillPath(ctx);
CGContextRestoreGState(ctx);

背景一直显示为白色而不是透明。椭圆也不会改变颜色并显示为黑色。提前感谢任何看一看的人。

【问题讨论】:

  • 您的视图的 opaque 属性是否已关闭?
  • 是的,恐怕它已经关闭了,但它仍然可以。

标签: ios uiview core-graphics drawrect cgpath


【解决方案1】:

我认为您可以参考此答案来解决您的透明度问题: Setting A CGContext Transparent Background

至于您的椭圆颜色问题,它在我的模拟器上正确显示为橙色椭圆,因此您可以检查代码中其他部分的可能覆盖或其他可能的副作用。

【讨论】:

  • 我是个白痴,我在 init 中将背景设置为清除,但在 awakeFromNib 中没有。但是感谢您的快速响应。
猜你喜欢
  • 2015-08-07
  • 1970-01-01
  • 2020-04-21
  • 2012-04-23
  • 1970-01-01
  • 1970-01-01
  • 2022-10-04
相关资源
最近更新 更多