Sun*_*Rao 2 objective-c uibutton uiimageview ios
如何改变tintColor的button.imageView.如果我使用UIImageView与下面相同的渲染模式使用相同的图像,tintColor则会改变,但按钮的图像视图不会发生相同的情况.是因为buttonType吗?
UIButton *frontButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[frontButton setImage:[[UIImage imageNamed:FRONT_IMAGE] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
[frontButton.imageView setTintColor:[UIColor redColor]];
[self addSubview:frontButton];
Run Code Online (Sandbox Code Playgroud)
设置按钮类型"系统",然后设置色调颜色.这个解决方案一定会奏效.请试试这个
UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
[btn setTintColor:YOUR_COLOR];
[btn setImage:YOUR_Image];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3015 次 |
| 最近记录: |