가이 코드에 사용자 지정있는 UIButton을 만들어 작동하지 않습니다아이폰 OS 설계 가능 단추 배경 색상
@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;
}
}
그것은 아주 간단한 코드입니다. 스토리 보드의보기에 내 버튼을 추가하면 완벽 해 보입니다. 그러나 앱을 재생할 때 버튼 배경색은 항상 밝은 회색입니다. 버튼을 누르면 배경색이 스토리 보드에서 선택한 색상으로 변경됩니다.
왜 이렇게할까요? 오류는 어디에 있습니까?
덕분에 수업이 추가) –