を動作しません。私はこのコードでカスタムUIButtonを作成しました:iOSの設計可能なボタンの背景色
@implementation HGButton
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self initVariables];
[self customInit];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self initVariables];
[self customInit];
}
return self;
}
- (void)drawRect:(CGRect)rect
{
[self customInit];
}
- (void)setNeedsLayout
{
[super setNeedsLayout];
[self setNeedsDisplay];
}
- (void)prepareForInterfaceBuilder
{
[self customInit];
}
-(void) initVariables
{
self.fillColor = [UIColor lightGrayColor];
self.borderWidth = 2;
self.cornerRadious = 10;
}
- (void)customInit
{
[self setBackgroundColor:self.fillColor];
self.layer.cornerRadius = self.cornerRadious;
self.layer.borderWidth = self.borderWidth;
if (self.cornerRadious > 0) {
self.layer.masksToBounds = YES;
}
}
、それは非常に簡単なコードです。ストーリーボードのビューにボタンを追加すると、完璧に見えます。 しかし、私は、アプリを再生ボタンの背景色は常に明るい灰色です。 ボタンを押すと背景色がストーリーボードで選択した色に変わります。
これはなぜですか?エラーはどこですか?
おかげで自分のクラスでこれを追加します。) –