Cha*_*lis 3 objective-c background-color uitableview
我有一个分组tableView,我试图将默认背景更改为自定义颜色.我看了一遍,最接近工作的是:
- (void)viewDidLoad {
UIColor *backgroundColor = [UIColor colorWithRed:181 green:293 blue:223 alpha:0];
self.tableView.backgroundView = [[UIView alloc]initWithFrame:self.tableView.bounds];
self.tableView.backgroundView.backgroundColor = backgroundColor;
}
Run Code Online (Sandbox Code Playgroud)
此代码将背景更改为白色,但我无法将其更改为自定义颜色.有人可以帮我吗?
您正在错误地创建颜色.RGBA值需要在0.0到1.0的范围内.UIColor将1.0以上的任何东西视为1.0.因此,您的颜色将设置为白色,因为所有三个RGB值都将被视为1.0.另请注意,alpha为0表示完全透明.你希望1.0意味着完全可见.
- (void)viewDidLoad {
UIColor *backgroundColor = [UIColor colorWithRed:181/255.0 green:293/255.0 blue:223/255.0 alpha:1.0];
self.tableView.backgroundView = [[UIView alloc]initWithFrame:self.tableView.bounds];
self.tableView.backgroundView.backgroundColor = backgroundColor;
}
Run Code Online (Sandbox Code Playgroud)
请注意,您的绿色值为293.需要将其更改为0到255之间的值.
| 归档时间: |
|
| 查看次数: |
2655 次 |
| 最近记录: |