在通用应用程序(iOS 5)中设置UITableView背景色

在通用应用程序(iOS 5)中设置UITableView背景色,uitableview,ios5,background-color,Uitableview,Ios5,Background Color,我必须在我的通用应用程序中将UITableView的backgroundColor属性设置为特定颜色。如果我写这个 self.tableView.backgroundColor = [UIColor colorWithRed:146.0f green:197.0f blue:240.0f alpha:1.0f]; …它在iPhone和iPad上都不起作用(背景结果为白色) 如果我使用标准颜色,那么 self.tableView.backgroundColor = [UIColor greenC

我必须在我的通用应用程序中将UITableView的backgroundColor属性设置为特定颜色。如果我写这个

self.tableView.backgroundColor = [UIColor colorWithRed:146.0f green:197.0f blue:240.0f alpha:1.0f];
…它在iPhone和iPad上都不起作用(背景结果为白色)

如果我使用标准颜色,那么

self.tableView.backgroundColor = [UIColor greenColor];
…它可以在iPhone上运行,但不能在iPad上运行


我尝试了其他建议的解决方案(backgroundView到nil/clearColor,等等),但这些都不适用于iosdk5。您能帮我吗?

您需要将每个颜色值除以255。 您的颜色将是:

[UIColor colorWithRed:146/255.0 green:197/255.0 blue:240/255.0 alpha:1.0];

您正在使用导航控制器吗

试试这个:

 self.tableView.backgroundColor = [UIColor clearColor];
[self.tableView setSeparatorColor:[UIColor clearColor]];
self.navigationController.view.backgroundColor = [UIColor greenColor];

这就是我在iOS5和一个通用应用程序中使用的内容。

您可以为tableView设置背景视图(使用您喜欢的背景颜色),而不是更改背景颜色

UIView *bgView = [[UIView alloc] initWithFrame:self.tableView.bounds];
bgView.backgroundColor = [UIColor redColor];
self.tableView.backgroundView = bgView;

您的RGB值应介于0.0f和1.0f之间。看,我也有同样的问题。对于配备iOS 5.0的iPad,tableview的背景色看起来无法更改。如果您能够解决问题,请发布答案。好的。我得了个负数。我知道我的答案只是答案的一半,因为你真的应该把数字除以255。但iPad的问题还在于将tableview背景设置为clearColor,因为它在iPad上的工作方式与iPhone不同。这就是为什么[UIColor greenColor]能在iPhone上工作而不能在iPad上工作的原因。