如何在 sd_setImageWithURL 加载的单元格中将 tintcolor 更改为 uiimage?
How to change tintcolor to uiimage in cell loaded by sd_setImageWithURL?
我正在将图像加载到自定义单元格上的 UIImageView 中。此图像是使用 UIImageView+WebCache.h 加载的,我想更改 tintColor,但我正在尝试此代码但无法更改颜色...
[cell.icon sd_setImageWithURL:[NSURL URLWithString:myURL
placeholderImage:[UIImage imageNamed:imageName options:SDWebImageRefreshCached];
UIImage* img = [UIImage imageNamed:imageName];
cell.icon.image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
cell.icon.tintColor = [UIColor yellowColor];
我该如何解决这个问题?
您应该使用带有完成块的 SDWebImage
函数。试试这个。
cell.icon.tintColor = [UIColor yellowColor];
[cell.icon sd_setImageWithURL:[NSURL URLWithString:myURL] placeholderImage:[UIImage imageNamed:imageName] options:SDWebImageRefreshCached completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
cell.icon.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}];
With Swift 5.0 You can use
cell.icon.tintColor = UIColor.yellow
cell.icon.sd_setImage(with: URL(string: myURL), placeholderImage: UIImage(named: imageName), options: SDWebImageRefreshCached, completed: { image, error, cacheType, imageURL in
cell.icon.image = image?.withRenderingMode(.alwaysTemplate)
})
我正在将图像加载到自定义单元格上的 UIImageView 中。此图像是使用 UIImageView+WebCache.h 加载的,我想更改 tintColor,但我正在尝试此代码但无法更改颜色...
[cell.icon sd_setImageWithURL:[NSURL URLWithString:myURL
placeholderImage:[UIImage imageNamed:imageName options:SDWebImageRefreshCached];
UIImage* img = [UIImage imageNamed:imageName];
cell.icon.image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
cell.icon.tintColor = [UIColor yellowColor];
我该如何解决这个问题?
您应该使用带有完成块的 SDWebImage
函数。试试这个。
cell.icon.tintColor = [UIColor yellowColor];
[cell.icon sd_setImageWithURL:[NSURL URLWithString:myURL] placeholderImage:[UIImage imageNamed:imageName] options:SDWebImageRefreshCached completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
cell.icon.image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}];
With Swift 5.0 You can use
cell.icon.tintColor = UIColor.yellow
cell.icon.sd_setImage(with: URL(string: myURL), placeholderImage: UIImage(named: imageName), options: SDWebImageRefreshCached, completed: { image, error, cacheType, imageURL in
cell.icon.image = image?.withRenderingMode(.alwaysTemplate)
})