简体   繁体   English

屏幕上的 Swift Tableview 标题

[英]Swift Tableview header on to of screen

I have setup a tableview in my VC with a custom header.我在我的 VC 中设置了一个带有自定义标题的 tableview。 I also have a Navigation bar which I have make it transparent.我还有一个导航栏,我已经让它透明了。 I want the tableview header to be on the top of the screen, not below the navigation bar.我希望 tableview 标题位于屏幕顶部,而不是导航栏下方。 I have tried to put -navigationBar.height in the CGRect y origin of the headerViewFrame but seems not working.我试图将 -navigationBar.height 放在 headerViewFrame 的 CGRect y 原点中,但似乎不起作用。

I have:我有: 在此处输入图片说明

And I want something like:我想要这样的东西: 在此处输入图片说明

Here is some code :这是一些代码:

func setupTableView() {
    let tableView = UITableView()
    tableView.frame = view.bounds
    tableView.backgroundColor = .blue
    view.addSubview(tableView)
    tableView.separatorStyle = .none
    tableView.tableHeaderView = headerView
}

lazy var headerView: LFHeaderView = {
    let headerView = LFHeaderView()
    headerView.frame = CGRect(x: 0, y: 0, width: SCREENW, height: 242)
    return headerView
}()

Thank you谢谢

try inseting the UITableView尝试插入 UITableView

[self.tableView setContentInset:UIEdgeInsetsMake(44,0,0,0)];

Alternatively in swift或者快速

self.tableView.contentInset = UIEdgeInsetsMake(44, 0, 0, 0)

Change your frame of headerView like更改您的 headerView框架,例如

headerView.frame = CGRect(x: 0, y: min(0, self.tableView.contentOffset.y), width: SCREENW, height: 242)

If Still facing issue then another option is go to如果仍然面临问题,则另一种选择是转到

Main.StoryBoard -> Select Your VC -> Attribute Inspector -> Do Check Under Top Bar. Main.StoryBoard -> 选择您的 VC -> 属性检查器 -> 在顶部栏下进行检查。

Look this answer, Here you need to do/apply check mark. 看看这个答案,在这里你需要做/应用复选标记。

尝试使用 UITableViewController 并使用:

tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?

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

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