ios StoryBoards 中的表头视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7841167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 21:58:20  来源:igfitidea点击:

Table Header Views in StoryBoards

iosuitableviewxcode4storyboard

提问by Tyler DeWitt

Is there a way to insert a Table Header View (tableHeaderView) in StoryBoard (like we used to do in Interface Builder)?

有没有办法在 StoryBoard 中插入表头视图(tableHeaderView)(就像我们过去在 Interface Builder 中所做的那样)?

回答by Mr Rogers

It looks like one simply drags a control to the top of the table view. I didn't expect it to be that easy.

看起来就像是简单地将一个控件拖到表格视图的顶部。我没想到会这么容易。

Before Drop

掉落前

Before Drop

掉落前

After Drop

掉落后

After Drop

掉落后

回答by PANKAJ VERMA

You can do this easily by dragging your UIView/UIImageViewjust below the UITableViewin the document outline (instead of the layout).

您可以通过在文档大纲(而不是布局)下方拖动您的UIView/ 来轻松完成此操作。UIImageViewUITableView

If you try to drag in the layout instead of document outline the UITableViewCellwill jump to the top handling which is frustrating!

如果您尝试拖动布局而不是文档大纲,UITableViewCell则会跳转到令人沮丧的顶部处理!

回答by Badr

Dragging and dropping a view on top of the tableview worked for only one screen size, at least in Xcode 11. It didn't size well on different screens.

至少在 Xcode 11 中,在 tableview 顶部拖放视图仅适用于一种屏幕尺寸。它在不同屏幕上的尺寸不太好。

I just created a view and left it there behind the tableview in storyboard. I created an IBOutlet for it:

我刚刚创建了一个视图并将其留在故事板中的 tableview 后面。我为它创建了一个 IBOutlet:

@IBOutlet weak var audioView: UIView!

Then in tableview code I did:

然后在 tableview 代码中我做了:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    return audioView
}

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 142
}

It worked well on all screen sizes.

它适用于所有屏幕尺寸。