我需要制作自己的 UITableViewCellAccessoryDisclosureIndicator,这样我才能拥有自定义颜色。我需要将背景设置为清除。无论我尝试什么,我都无法让 clearColor 工作。当我将下面的 CGContextSetFillColorWithColor 行更改为 redColor 时,它是红色的。我试过设置不透明和 backgroundColor,然后调用 super drawRect 并删除我的填充代码并显示我的填充代码,但它仍然不好。我还以各种方式尝试了 CGContextClearRect。
这是模拟器中的红色版本。我需要 UIView 清晰可见,以便显示漂亮的背景图像。
我不太关心滚动性能,因为这个表的行数很少。
- (instancetype) init {
self = [super init];
if (!self) return nil;
// [self setOpaque:NO];
// [self setBackgroundColor:[UIColor clearColor]];
return self;
}
- (void)drawRect:(CGRect)rect {
// [super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
// my obviously silly/naive attempt at making the background clear
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor); // redColor works
CGContextFillRect(context, rect);
// drawing code for chevron
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetLineWidth(context, 3.f);
CGContextSetLineJoin(context, kCGLineJoinMiter);
CGContextMoveToPoint(context, PADDING, PADDING);
CGContextAddLineToPoint(context, self.frame.size.width - PADDING, self.frame.size.height/2);
CGContextAddLineToPoint(context, PADDING, self.frame.size.height - PADDING);
CGContextStrokePath(context);
CGContextRestoreGState(context);
}
最佳答案
这个怎么样?
self.contentView.opaque = NO;
self.backgroundColor = [UIColor clearColor];
关于ios - 我的自定义 UIView 如何绘制清晰的背景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24914085/