简体   繁体   English

无法摆脱UITableView的tableFooterView中的颜色

[英]Can't get rid of color in UITableView's tableFooterView

I have a standard UITableView with three sections. 我有一个包含三个部分的标准UITableView。 At the bottom of the table I'm trying to add a tableFooterView . 在表格的底部,我试图添加一个tableFooterView It seems as though there's a standard spacing between the last row in the table and the top of the tableFooterView , which is fine, but my problem is that there is a different color in this spacing that I can't get rid of. 似乎表格的最后一行和tableFooterView的顶部之间有一个标准间距,这很好,但是我的问题是在这个间距中有一种我无法摆脱的不同颜色。 I need that spacing to match the background of my tableView . 我需要该间距以匹配tableView的背景。

Here's some code: 这是一些代码:

self.menuTable.backgroundColor = [UIColor redColor];
self.menuTable.backgroundView = nil;
self.menuTable.separatorColor = [UIColor clearColor];
self.menuTable.delegate = self;
self.menuTable.sectionHeaderHeight = 10.0;

UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 200)];
footer.backgroundColor = self.menuTable.backgroundColor;
UILabel *footerLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 0, 205, 100)];
footerLabel.text = @"foo bar.";
footerLabel.textColor = [UIColor blackColor];
footerLabel.backgroundColor = self.menuTable.backgroundColor;
footerLabel.numberOfLines = 10;
footerLabel.font = [UIFont italicSystemFontOfSize:11.0];
[footerLabel sizeToFit];

[footer addSubview:footerLabel];
self.menuTable.tableFooterView = footer;

Here's a screenshot (sorry about the red, but it's the easiest way to see the differences in colors). 这是一个屏幕截图(对不起红色,但这是查看颜色差异的最简单方法)。

在此处输入图片说明

Whoops. 哎呦。 Earlier I was trying to add a sectionFooterView, and had implemented tableView:heightForFooterInSection: , returning 20 for the last section. 早些时候,我尝试添加一个sectionFooterView,并实现了tableView:heightForFooterInSection:为最后一部分返回20。 That's where that gap was coming from, and it had a default color of white. 这就是间隙的来源,它具有默认的白色。 Since I'm now placing the text as the tableFooterView , I just removed that delegate callback and everything is rendering as expected. 由于我现在将文本放置为tableFooterView ,因此我刚刚删除了该委托回调,并且一切都按预期方式呈现。

Try this 尝试这个

self.menuTable.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [UIColor redColor];

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

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