这个让我难过.
是否有可能在iPhone的Cocoa中更改UIButton的背景颜色.我尝试过设置背景颜色,但只改变了角落.setBackgroundColor:似乎是唯一可用于此类事情的方法.
[random setBackgroundColor:[UIColor blueColor]];
[random.titleLabel setBackgroundColor:[UIColor blueColor]];
Run Code Online (Sandbox Code Playgroud) 我UIButton在循环中以编程方式创建了一些s但是我在设置按钮的背景颜色方面遇到了一些问题.
按钮的颜色始终显示为白色.但是我只使用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];
Run Code Online (Sandbox Code Playgroud)