私はUIButtonのサブクラスを作成して白い2px No Radiiボーダーを作成しましたが、今はボタンの状態に応じてフォント、フォント色、および背景色を「グローバルに」設定しようとしています。UIButtonサブクラス - プロパティの設定?
フォントが設定されていません。色も背景色もしないでください。どうしたの?ここに私のコードです。私はあなたが助けることを望む:)
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[[self titleLabel] setFont:[UIFont fontWithName:@"ZegoeUI" size:18]];
[self setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
[self setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
if(self.state == UIControlStateHighlighted) {
[self setBackgroundColor:[UIColor whiteColor]];
}
else {
[self setBackgroundColor:[UIColor blackColor]];
}
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
[self.layer setMasksToBounds:YES];
[self.layer setBorderWidth:2.0];
[self.layer setCornerRadius:0.0];
[self.layer setBorderColor:[[UIColor colorWithWhite:1.0 alpha:1.0] CGColor]];
}
私は何か間違っているとは思わない。私はこのクラスを持っている、とIBのボタンをリンクしている、とクラスタイプを設定し...
おかげで、
ベンベン
私は正確にそれについて正確にどのように行きますか?私は大学に行ったことは一度もありません。これまでに教えられているのはすべてです。 – topLayoutGuide
あなたと私の両方:)。更新された回答を参照 – jrturton