我有我自己的UIButton个子类.我在上面加了UIImageView,然后加了一张图片.我想用浅色把它涂在图像上,但是不行.

到目前为止,我有:

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        self.backgroundColor = [UIColor clearColor];
        self.clipsToBounds = YES;

        self.circleView = [[UIView alloc]init];
        self.circleView.backgroundColor = [UIColor whiteColor];
        self.circleView.layer.borderColor = [[Color getGraySeparatorColor]CGColor];
        self.circleView.layer.borderWidth = 1;
        self.circleView.userInteractionEnabled = NO;
        self.circleView.translatesAutoresizingMaskIntoConstraints = NO;
        [self addSubview:self.circleView];

        self.iconView = [[UIImageView alloc]init];
        [self.iconView setContentMode:UIViewContentModeScaleAspectFit];
        UIImage * image = [UIImage imageNamed:@"more"];
        [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        self.iconView.image = image;
        self.iconView.translatesAutoresizingMaskIntoConstraints = NO;
        [self.circleView addSubview:self.iconView];
        ...

关于 Select :

- (void) setSelected:(BOOL)selected
{
    if (selected) {
        [self.iconView setTintColor:[UIColor redColor]];
        [self.circleView setTintColor:[UIColor redColor]];
    }
    else{
        [self.iconView setTintColor:[UIColor blueColor]];
        [self.circleView setTintColor:[UIColor blueColor]];
    }  
}

我做错什么了?(图像的 colored颜色 始终保持与原始 colored颜色 相同.)

推荐答案

与此代码不同的是:

[image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

您应该已经:

image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

Swift 4.1里用这个

image = UIImage(named: "name")!.withRenderingMode(.alwaysTemplate)

Ios相关问答推荐

如何在iPhone 15上消除.NET Maui中状态栏和页面之间的差距

有没有办法观察滚动的SwiftUI图表的内容偏移量?

当操作修改查看条件时,按钮不重复

在 Android 和 iOS 应用程序上下文中阻止后台线程有哪些缺点?

iOS设备网页自动化中,在向字段发送文本后未启用按钮

在Xcode 15中为具有@Binding的视图创建SwiftUI #预览的方法

在 iOS 上启用明文本地流量在 .NET MAUI 中不起作用

SwiftUI 菜单中的内联水平按钮

SwiftUI:如何为 ScrollView 制作可拉伸(灵活)的粘性标题?

JSONDecoder 在模拟器上运行良好时无法在真实设备上解码

在 tableview 中下载图像缩略图时如何提高滚动性能

如何在 iPhone 中为透明的 PNG 图像着色?

如何在上传到服务器之前在 iOS 上压缩/调整图像大小?

如何计算 Swift 数组中元素的出现次数?

文件是为存档而构建的,它不是被链接的体系 struct (i386)

UINavigationBar - 以编程方式设置标题?

iPhone:什么是 WWDR 中级证书?

从 iOS/Android 上的 Web 应用调用本机日期 Select 器

NSURL 到带有 XCTest 的测试包中的文件路径

iOS 中的 Google Analytics SDK 3.0 _sqlite3 链接器错误