ループを使用してボタンを作成し、プロパティを設定してボタンを合成しました。今、別のView Controllerでボタンの色を変更したいと思います。各ボタンのタグ値を設定しています。ボタンを選択すると、別のView Controllerでタグ値を適切に取得できます。次に、各ボタンの背景色を変更したいと思います。
これがサンプルコードです。
CustomView.h 内
UIButton *customBtn;
property (nonatomic, strong) UIButton *customBtn;
@synthesize customBtn;
CustomView.m 内
for (int i=0; i<=[resultArray count]; i++)
{
customBtn= [UIButton buttonWithType:UIButtonTypeCustom];
customBtn = CGRectMake(X, 30, 20, 20); notsupport = [[UILabel alloc]initWithFrame:CGRectMake(25, 30, 290, 20)];
[customBtn addTarget:customDelegate actionselector(MyAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:customBtn];
X = X + 30;
}
ビューコントローラーで:
viewController.customBtn.backgroundColor = [UIColor blackColor];
すべてのボタンの背景色に影響するので、各ボタンの背景色を変更するにはどうすればよいですか。すべてのボタンに対して個別のインスタンスを作成している場合、ボタンの背景色を変更できます。ボタンの 1 つのインスタンスを使用して、ボタンの背景色を変更するにはどうすればよいでしょうか。
私を助けてください。
ありがとう!