TableView backgroundColor不变 [英] TableView backgroundColor not changing

查看:114
本文介绍了TableView backgroundColor不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分组的tableView,并且试图将默认背景更改为自定义颜色.我到处都看了,最接近工作的是:

I have a grouped tableView, and I am trying to change the default background to custom color. I have looked all over, and the closest thing to working is this:

- (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;
}

此代码将背景更改为白色,但是我无法将其更改为自定义颜色.有人可以帮我吗?

This code changes the background to white, but I can't get it to change to the custom color. Can someone help me out?

推荐答案

您创建的颜色不正确. RGBA值必须在0.0-1.0的范围内. UIColor会将超过1.0的任何内容视为1.0.因此,将您的颜色设置为白色,因为所有三个RGB值都将被视为1.0.另请注意,alpha为0表示完全透明.您希望1.0表示完全可见.

You are creating the color incorrectly. The RGBA values need to be in the range 0.0 - 1.0. UIColor will treat anything over 1.0 as 1.0. So your color is being set to white since all three RGB values will be treated as 1.0. Also note that an alpha of 0 means totally transparent. You want 1.0 to mean totally visible.

- (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;
}

请注意,您的绿色值为293.需要将其更改为0到255之间的某个值.

Please note that your green value is 293. That needs to be changed to something from 0 to 255.

这篇关于TableView backgroundColor不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆