简体   繁体   English

自定义表视图背景的UITableViewCell颜色问题

[英]UITableViewCell color issues with custom table view background

I have a UITableView with a custom background image set like this: 我有一个UITableView,其自定义背景图像设置如下:

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"mybg.png"]];

The background appears fine, but my UITableViewCells (default cells, not custom) have some sort of weird tint to them, and the UILabel containing the "New Project" text also seems to have some sort of background behind it. 背景看起来很好,但我的UITableViewCells(默认单元格,而不是自定义)对它们有一些奇怪的色调,包含“新项目”文本的UILabel似乎也有一些背景。 How can I remove this? 我该如何删除? I've already tried: 我已经尝试过了:

cell.backgroundColor = [UIColor clearColor];
cell.textLabel.backgroundColor = [UIColor clearColor];

Thanks 谢谢

alt text http://cl.ly/Cg5/content alt text http://cl.ly/Cg5/content

I believe that this is a nasty side-effect of simply adding an image straight into your table view's backgroundColor. 我相信这是一个令人讨厌的副作用,只需将图像直接添加到表视图的backgroundColor中。

Try adding the image to the view 's background color: 尝试将图像添加到视图的背景颜色:

[[self view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"mybg.png"]]];

and then set the table view 's backgroundColor to be clear: 然后将表视图的backgroundColor设置为clear:

[[self tableView] setBackgroundColor:[UIColor clearColor]];

I hope this helps! 我希望这有帮助!

Some times when your working with setting images for an app, and testing on the simulator, they get frozen to the app for the few run. 有时,当你为应用程序设置图像并在模拟器上进行测试时,它们会被冻结到应用程序中进行少数运行。 Not sure, this is the case even if you delete the image files; 不确定,即使删除图像文件也是如此; they still keep popping up. 他们仍然不断涌现。

I would make that you have rest the simulator, and restart Xcode. 我会让你休息模拟器,并重新启动Xcode。 Then force a rebuild of the app back on the simulator. 然后在模拟器上强制重建应用程序。 This should clear out any images- even background images if they are still being referenced. 这应该清除任何图像 - 如果仍然被引用的背景图像。

If this is not a solution that works...try making sure that you don't have conflicting commands going to the same UiTablView object-(1 from IB and 1 from Xcode programmically). 如果这不是一个有效的解决方案...请确保您没有冲突的命令转到相同的UiTablView对象 - (1来自IB,1来自Xcode,程序化)。 Sometimes you can overlook that you have set something in IB, and it conflicts with what your telling it to do programically. 有时你可能会忽略你在IB中设置了某些内容,并且它与你通过编程方式所做的事情相冲突。

If that doesn't solve the issue...check the connections in IB and make sure your reffrencing the correct IBOutlet UITableView *tableview. 如果这不能解决问题...检查IB中的连接并确保您重新获得正确的IBOutlet UITableView * tableview。 And you have the delegat and data protocols in the header. 并且您在头文件中有委托和数据协议。

If you want to have each cell set with background and want to remove text's background, maybe you can try this... 如果你想让每个单元格都有背景并想要删除文本的背景,也许你可以尝试这个......


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

- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"mybg.png"]];
cell.textLabel.backgroundColor = [UIColor clearColor];
...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM