Search code examples
iosobjective-cuiimageviewuibutton

tintColor of UIButton's ImageView is not changing


How to change tintColor of button.imageView. If I use the same image in UIImageView with the same rendering mode as below the tintColor will change but the same is not happening for button's image view. Is it because of buttonType ?

    UIButton *frontButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [frontButton setImage:[[UIImage imageNamed:FRONT_IMAGE] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal];
    [frontButton.imageView setTintColor:[UIColor redColor]];
    [self addSubview:frontButton];

Solution

  • Set Button type "System" and then set tint color. This solution will definitely work. Please try this

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
     [btn setTintColor:YOUR_COLOR];
     [btn setImage:YOUR_Image];