且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何使用CGContext在UIView中设置背景颜色?

更新时间:2023-11-09 23:18:10

这段代码怎么样?

- (void)drawRect:(CGRect)rect {

    [super drawRect:rect];
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGRect drawRect = CGRectMake(rect.origin.x, rect.origin.y,rect.size.width, rect.size.height);

    CGContextSetRGBFillColor(context, 100.0f/255.0f, 100.0f/255.0f, 100.0f/255.0f, 1.0f);
    CGContextFillRect(context, drawRect);
}