2017-01-09 28 views
1

私は目的のアプリケーションにUIButtonを持っています。私のボタンは同様にテキストや画像を追加する修正されました:imageEdgeInsetsを使用してUIButtonでイメージのtintColorを変更するにはどうすればよいですか?

- (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); 
} 

そして私は、このコードで画像を追加します、私は画像のtintColorを変更したい

[self.myButton setImage:[UIImage imageNamed:@"imageButton.png"] forState:UIControlStateNormal]; 

が、私はこれを変更しようとすると、私のコードは動作しません。

[self.myButton setTintColor:[UIColor redColor]]; 

を、私はこのコードを使用しようとしているが、うまくいきませんでした:

enter image description here

がどのように私はIMAGEBUTTONの色を変えることができる:私はそれを取得したい enter image description here

:10

私はこれを持っていますか?

+0

このリンクを参照してください。http://stackoverflow.com/questions/12396236/ios-change-the-colors-of-a -uiimage –

答えて

1

変更

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeCustom]; 

変更して、プログラムでInterface BuilderでUIButtonTypeCustomにUIButtonTypeしたり、独自の属性と丸みを帯びた角に

myButton.backgroundColor = [UIColor redColor]; 
myButton.layer.borderColor = [UIColor blackColor].CGColor; 
myButton.layer.borderWidth = 0.5f; 
myButton.layer.cornerRadius = 10.0f; 

を再作成

+0

私のボタンがストーリーボードに追加されたIBOutletであれば、これをどのように適用できますか? – user3745888

+0

@ user3745888ストーリーボードのボタンを選択するとタイプが表示され、カスタムに変更されます –

+0

これを追加しましたが、これは背景を変更します。これはuiimageの色を変更しません。 – user3745888

1
..私は状況をお知らせ

レイヤーを作成し、このようなボタンでImageView上で目的のカラーとマスクを設定します。

0

透明アイコンには、次の方法で希望の色を適用できます。

1.画像をAssets.xcassetsにドラッグし、アセット属性インスペクタでレンダリング属性をTemplate Imageに変更します。

enter image description here

2.And方法以下のような必要な色合いの色を設定します。

icon.tintColor = [UIColor redColor]; 

ご希望の場合はお手数ですが、我々は正しくtintColorプロパティを設定することができ、このコードでボタンに

[self.myButton setImage:[[UIImage imageNamed:@"myImageButton.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate] forState:UIControlStateNormal]; 

次に設定画像::このコードで

imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate 

:tintColorプロパティを変更するには

1

ソリューションをされたrenderingModeでsetImageた

self.myButton.tintColor = [UIColor redColor]; 
関連する問題