【发布时间】:2012-12-28 07:29:24
【问题描述】:
我已经使用循环创建了按钮并设置了属性并合成了按钮。现在我想更改另一个视图控制器中的按钮颜色。我正在为每个按钮设置标记值,并且在选择按钮时,我可以在另一个视图控制器中正确获取标记值。现在我想更改每个按钮的背景颜色。
这里是示例代码,
在 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];
它确实会影响所有按钮的背景颜色,所以我如何更改每个按钮的背景颜色。如果我为所有按钮创建单独的实例,我可以更改按钮的背景颜色。使用按钮的单个实例,我们如何改变按钮背景的颜色。
请帮帮我。
谢谢!
【问题讨论】:
标签: iphone objective-c background uibutton