我创建了一些UIButton
s以循环方式编程,但我在设置按钮的背景颜色时遇到了一些问题。Iphone UIButton背景颜色
按钮的颜色总是显示为白色。 但工作正常,我只在backgroundcolor中使用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];
+1绝对如此。同意。组件是0-1而不是0-255。 – Steve
谢谢!我总是尽管它是rgb的数字值而不是百分比值。 – Tim