Skip to content

第三方登录icon渲染变虚:【自己解决】 #7

@BackWorld

Description

@BackWorld
// 重新渲染图片
    class func imageNewColor(imageName:String, color: UIColor) -> UIImage{
        let image = UIImage(named: imageName)!
        // 高清图 @2x 不然会虚
        let size = CGSizeMake(image.size.width * 2, image.size.height * 2)
        UIGraphicsBeginImageContext(size)

        let context = UIGraphicsGetCurrentContext();

       // 高清图 @2x 不然会虚
        CGContextTranslateCTM(context, 0, size.height);

        CGContextScaleCTM(context, 1.0, -1.0);
        CGContextSetBlendMode(context, .Normal);

       // 高清图 @2x 不然会虚
        let rect = CGRectMake(0, 0, size.width, size.height);

        CGContextClipToMask(context, rect, image.CGImage);
        color.setFill()
        CGContextFillRect(context, rect);
        let newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return newImage;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions