IPad 的背景颜色总是灰色

当我为我的 UITableView设置 backgroundColor时,它在 iPhone (设备和模拟器)上工作得很好,但在 iPad 模拟器上就不行了。相反,我得到一个浅灰色背景的任何颜色,我设置包括 groupTableViewBackgroundColor

复制步骤:

  1. 创建一个新的基于导航的项目。
  2. 打开 RootViewController.xib 并将表视图样式设置为“ Groupe”。
  3. 将此响应器添加到 RootViewController: < br > < br > < pre > < code >-(void) viewDidLoad { [ super viewDidLoad ] ; 背景色 = [ UIColor blackColor ] ; }
  4. 选择 Simulator SDK 3.2,构建并运行。
  5. 你会得到一个黑色的背景(设备和模拟器)。
  6. 在项目树中选择目标。
  7. 点击项目: 升级 iPad 的当前目标。
  8. 构建并运行。
  9. 你会得到一个浅灰色的背景。
  10. 将表格视图样式恢复为“普通”,您将得到一个黑色背景。

谢谢你的帮助!

43955 次浏览

尝尝这个。

[myTableView setBackgroundView:nil];
[myTableView setBackgroundView:[[[UIView alloc] init] autorelease]];

非常感谢这个解决方案。 我在 UIViewController 中使用 IBOutlet 将其应用于 UITableView 属性,它的工作方式如下:

[panelTable setBackgroundView:nil];
[panelTable setBackgroundView:[[[UIView alloc] init] autorelease]];
[panelTable setBackgroundColor:UIColor.clearColor]; // Make the table view transparent

在 iPad 上,backgroundView属性似乎用于为分组表创建灰色背景色。因此,为了改变 iPad 上分组表格的背景颜色,应该先输出 backgroundView属性,然后在所需的表格视图上设置 backgroundColor

- (void)viewDidLoad
{
[super viewDidLoad];


// If you need to support iOS < 3.2, check for the availability of the
// backgroundView property.
if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) {
self.tableView.backgroundView = nil;
}
self.tableView.backgroundColor = [UIColor whiteColor];
}

如果你的应用同时面向 iPhone 和 iPad,你可以这样做:

[myTableView setBackgroundColor:[UIColor clearColor]]; // this is for iPhone


if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPhone) {
[myTableView setBackgroundView:nil];
[myTableView setBackgroundView:[[UIView alloc] init]];
} // this is for iPad only

请注意,TableView 分配对于 ARC 没有自动发布。

如果你正在给另一个 UIViewController 添加一个 UIViewController,那么除了 UITableView 之外,你还需要将视图的背景设置为 clearColor,否则你将得到一个白色的背景而不是浅灰色。

if ([myViewController.myTableView respondsToSelector:@selector(setBackgroundView:)]) {
[myViewController.myTableView setBackgroundView:nil];
}
myViewController.myTableView.backgroundColor = [UIColor clearColor];
myViewController.view.backgroundColor = [UIColor clearColor];

试着设置桌面的背景色和视图,但是运气不好(Xcode 5 iOS7.1 iPad 模拟器) ,iPhone 看起来还行,但是 iPad 的背景色是浅灰色..。

在 iOS7.14/2014上为我修复了这个

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


static NSString *CellIdentifier = @"ViewSomeTriggerCell";


// get a cell or a recycled cell
sictVCViewSomeTriggerCell *cellTrigger = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];


// put a picture and a word in the cell (positions set in .xib)
NSString * tname = [self.fetchedTriggersArray objectAtIndex:indexPath.row];
cellTrigger.imageTrigger.image = [UIImage imageNamed:@"icon_appicon.png"];
cellTrigger.labelName.text = tname;


// set background color, defeats iPad wierdness
// http://stackoverflow.com/questions/2688007/uitableview-backgroundcolor-always-gray-on-ipad


// clearColor is what I wanted, and it worked, also tested with purpleColor
cellTrigger.backgroundColor =[UIColor clearColor];
return cellTrigger;

}

我认为值得注意的是,对于 Xcode 6.1和 iOS 8.1,特别是 iPad (如果你也想设置单元格背景) ,似乎必须设置表格背景和单元格背景。

例如,在 iPhone 情节串连图板上,您可以设置一个单元格来清除颜色,然后通过编程为一个带有背景图像的透明表设置表的背景图像。然而,如果你在 iPad 上查看同样的配置,单元格就不清楚了。细胞将需要设置为清除程序为 iPad。

  • 模拟 iPad2
  • 运行 iOS 7.1到8.3
  • 由 XCode 6.3构建

以上这些都不适用于我的 UIViewController-> UITableView,它是使用单个 XIB 指定的。真正起作用的是将整个设置移动到故事板中,并使用 IB 检查器设置背景颜色。

我也有这样的问题。无论我设置什么背景颜色,UITableView总是 groupTableViewBackgroundColor

症状就像这个问题-UITableView 在显示视图之前正在重置其背景颜色

init函数中设置背景颜色后,它是正确的。在 viewDidLoadviewWillAppear阶段,这是正确的。但是,在 viewDidAppear中,背景颜色被重置为默认颜色。

公认的答案现在不起作用。

[myTableView setBackgroundView:nil];
[myTableView setBackgroundView:[[UIView alloc] init]];

这里是我的解决方案。 只需在 viewDidLoad函数中设置 tableView 的背景色而不是 initviewWillAppear

- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.backgroundColor = [UIColor clearColor];
}