【发布时间】:2011-09-29 07:05:41
【问题描述】:
我在循环中以编程方式创建了一些UIButtons,但在设置按钮的背景颜色时遇到了一些问题。
按钮的颜色始终显示为白色。 但是我在背景色中只使用了 2 种颜色,效果很好。 例如:红色:255 绿色:0 蓝色:200
这是我用来添加按钮的代码。
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(80, 20 + (i*75), 200, 75);
button.layer.cornerRadius = 10;
button.layer.borderWidth = 1;
[button setTitle:@"saf" forState:UIControlStateNormal];
[button addTarget:self action:@selector(moveLocation:) forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundColor:[UIColor colorWithRed:255 green:180 blue:200 alpha:1]];
button.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[scrollView addSubview:button];
【问题讨论】:
标签: iphone objective-c uibutton background-color