How i set the background color in UIView using CGContext?

前端 未结 2 2045
渐次进展
渐次进展 2021-02-20 01:10

I have developed the application in which i want to set the background color of UIView which is already set on UIViewController.The code is below,

@implementatio         


        
2条回答
  •  感动是毒
    2021-02-20 01:42

    How about this code?

    - (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);
    }
    

提交回复
热议问题