ios - XIB 中 UIImage 的色调

标签 ios uiimageview xib

我尝试了不同的方法,但没有找到这个问题的答案。 有没有办法对 XIB 文件中 UIImageView 定义的图像进行着色?

谢谢

最佳答案

这有效

- (UIImage *)imageWithBurnTint:(UIColor *)color
{
    UIImage *img = self;

    // lets tint the icon - assumes your icons are black
    UIGraphicsBeginImageContextWithOptions(img.size, NO, 0.0);
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextTranslateCTM(context, 0, img.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);

    CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);

    // draw alpha-mask
    CGContextSetBlendMode(context, kCGBlendModeNormal);
    CGContextDrawImage(context, rect, img.CGImage);

    // draw tint color, preserving alpha values of original image
    CGContextSetBlendMode(context, kCGBlendModeSourceIn);
    [color setFill];
    CGContextFillRect(context, rect);

    UIImage *coloredImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return coloredImage;

}

然后

[anImageViewInXib setImage:[center.image imageWithBurnTint:[UIColor blackColor]]];

关于ios - XIB 中 UIImage 的色调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18913336/

相关文章:

ios - 在 UIViewController 中加载一个 nib 文件

ios - Phonegap 3.8.0 & iOS8 状态栏

ios - 使用 To One 类型保存托管对象

ios - 动态静态 TableView

ios - 更新到 Xcode 7.0.1 后上传 iOS 应用程序时出错

ios - Xib 方法是否会在不久的将来因为 Storyboard而被弃用?

ios - 如何在 iOS 13 Web 应用程序中禁用 "Reader View"面板?

ios - 使用 tableView 的图像列表中的自动布局错误

swift - 我正在尝试在 UIImageView 中显示照片库中的图像

ios - 多个方向更改后转换后的 UIView 框架困惑