How to create a CGBitmapContext which works for Retina display and not wasting space for regular display?

后端 未结 4 2004
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 08:41

Is it true that if it is in UIKit, including drawRect, the HD aspect of Retina display is automatically handled? So does that mean in drawRect, th

4条回答
  •  有刺的猬
    2020-12-08 09:11

    Also try this one:

    - (UIImage *)maskImageWithColor:(UIColor *)color
    {
        CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
        UIGraphicsBeginImageContextWithOptions(rect.size, NO, self.scale);
        CGContextRef c = UIGraphicsGetCurrentContext();
        [self drawInRect:rect];
        CGContextSetFillColorWithColor(c, [color CGColor]);
        CGContextSetBlendMode(c, kCGBlendModeSourceAtop);
        CGContextFillRect(c, rect);
        UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return result;
    }
    

提交回复
热议问题