简体   繁体   English

如何使UITableView的节标题完全透明

[英]How to make the section header of a UITableView completely transparent

I have a UIViewController with a UIImage as the entire background image. 我有一个UIViewControllerUIImage作为整个背景图像。 I put a UITableView into my view controller and constraint it to the bottom, leading, trailing and half the height. 我将UITableView放入我的视图控制器中,并将其约束到底部,前导,尾随和一半高度。

The goal is to make the Section Header of the table view be completely transparent so that the background image is visible through the section header. 目的是使表格视图的“节标题”完全透明,以便可以通过节标题看到背景图像。

Doing this just makes it gray and not clear/transparent: 这样做只会使其变成灰色并且不清晰/透明:

self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.opaque = NO;

How can I make it transparent? 如何使其透明?

If you declared your tableHeader view using self.tableView.tableHeaderView = YourHeaderView ; 如果您使用self.tableView.tableHeaderView = YourHeaderView声明了tableHeader视图;

Update it by 更新方式

UIView *tempTableView = self.tableView.tableHeaderView;

then modify it by: tempTableView.backgroundColor = [UIColor clearColor]; 然后通过以下方式tempTableView.backgroundColor = [UIColor clearColor];进行修改: tempTableView.backgroundColor = [UIColor clearColor];

of directly like: self.tableView.tableHeaderView.backgroundColor = [UIColor clearColor]; 直接像这样: self.tableView.tableHeaderView.backgroundColor = [UIColor clearColor];

but if you are using UITableView Delegate: 但是,如果您使用的是UITableView委托:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

your need to update it by: 您需要通过以下方式进行更新:

UIView *tempTableView = [self.tableView viewForHeaderInSection:YourSection];

then modify: tempTableView.backgroundColor = [UIColor clearColor]; 然后修改: tempTableView.backgroundColor = [UIColor clearColor];

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

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