次のコードを使用してボタンの色を変更しました。
[self.testButton setBackgroundColor:[UIColor redColor]];
しかし、私は奇妙なボタンを手に入れました:
ボタンの背景色が変わらないのはなぜですか?
次のコードを使用してボタンの色を変更しました。
[self.testButton setBackgroundColor:[UIColor redColor]];
しかし、私は奇妙なボタンを手に入れました:
ボタンの背景色が変わらないのはなぜですか?
これをインポート#import <QuartzCore/QuartzCore.h>
して試すことができます。
self.testButton = [UIButton buttonWithType:UIButtonTypeCustom];
self.testButton.backgroundColor = [UIColor redColor];
self.testButton.layer.borderColor = [UIColor blackColor].CGColor;
self.testButton.layer.borderWidth = 0.5f;
self.testButton.layer.cornerRadius = 10.0f;
または、このボタンの背景画像としてカスタム画像を使用することもできます。
.xib の属性インスペクターでボタンの種類をカスタムに変更し、コードを確認します。
[self.testButton setBackgroundColor:[UIColor redColor]];