改变iOS应用中UITableView的背景颜色与背景图片的方法

前端技术 2023/09/02 IOS

改变UITableView的header、footer背景颜色

改变UITableView的header、footer背景颜色,这是个很常见的问题。之前知道的一般做法是,通过实现tableView: viewForHeaderInSection:返回一个自定义的View,里面什么都不填,只设背景颜色。但是今天发现一个更简洁的做法:

对于iOS 6及以后的系统,实现这个新的delegate函数即可:

复制代码 代码如下:

- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section {
 view.tintColor = [UIColor clearColor];
}

还可以改变文字的颜色:
复制代码 代码如下:

- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section
{
 UITableViewHeaderFooterView *footer = (UITableViewHeaderFooterView *)view;
 [footer.textLabel setTextColor:[UIColor whiteColor]];
}

修改tableView的背景图片

修改UITableView的背景图片

1.图片显示为\'PatternImage\'模式。

复制代码 代码如下:

// viewDidLoad

self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@\"BackgroundImage\"]];

// cellForRowAtIndexPath

cell.backgroundColor = [UIColor clearColor];

本文地址:https://www.stayed.cn/item/4414

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。