2016-05-11 7 views
0

tintColorbutton.imageViewに変更する方法です。 UIImageViewと同じレンダリングモードで同じ画像を使用すると、tintColorは変わりますが、ボタンの画像ビューでは同じことは起こりません。 buttonTypeのためですか?UIButtonのImageViewのtintColorが変更されていません

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

[リンク](http://stackoverflow.com/questions/14511639/how-to-tint-the-background-images-of-an-uibutton-programmatically-and-dynamicall)希望をお試しくださいこのリンクはあなたを助けます。 –

答えて

5

ボタンの種類を「システム」に設定し、色合いを設定します。 このソリューションは間違いなく機能します。この

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

[btn setBackgroundImage:Your_Image]を使用できますか? ? –

+1

はい、Uは –

+0

を使用できますが、両方に違いはありますか? –

2

ボタンの内側に色合いの色を変更するには、このコードを試してみてください。

UIButton *frontButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:FRONT_IMAGE]]; 
imageV.image = [imageV.image imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 
imageV.tintColor = [UIColor redColor]; 
[frontButton setImage:imageV.image forState:UIControlStateNormal]; 
0

私は答えを見つけて、私はちょうど述べたようにレンダリングモードを設定した後でないボタンのimageViewプロパティにUIButtontintColorを与える必要があり質問に。

[button setTintColor:YOUR_COLOR]; 
1

あなたはボタンに何かのように、

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

設定色合いの色を行うことができますし、画像レンダリングモードがテンプレートである場合、それはまた、この色合いの色を取得します。

ボタンの色合いが異なり、画像が異なる場合は、一時的な画像ビューを1つ取って、その画像ビューにレンダリングモードのテンプレートを設定し、色合いをその画像ビューに設定し、その画像ビューのボタンに画像を設定する必要があります。

希望します。

関連する問題