我的 Objective-C 应用程序中有一个 UIButton。我的按钮已修改,添加了文本和图像,例如:
- (void)centerButtonAndImageWithSpacing:(CGFloat)spacing {
CGFloat insetAmount = spacing / 2.0;
self.imageEdgeInsets = UIEdgeInsetsMake(0, -insetAmount, 0, insetAmount);
self.titleEdgeInsets = UIEdgeInsetsMake(0, insetAmount, 0, -insetAmount);
self.contentEdgeInsets = UIEdgeInsetsMake(0, insetAmount, 0, insetAmount);
}
然后我用这段代码添加图像:
[self.myButton setImage:[UIImage imageNamed:@"imageButton.png"] forState:UIControlStateNormal];
我想更改图像的 tintColor,但是当我尝试更改时,我的代码不起作用:
[self.myButton setTintColor:[UIColor redColor]];
我正在尝试使用此代码,但没有奏效:
UIImage* img = [UIImage imageNamed:imageName];
icon.image = [img imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
icon.tintColor = [UIColor redColor];
如何更改 imageButton 的颜色?