创建类似 iOS 的设置屏幕
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24965324/
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
Creating iOS-like settings screen
提问by user3746428
I have been researching how I can create a settings screen for my app that looks identical to the iOS settings app however I haven't been able to find an iOS 7/8/Swift version. I have a custom designed settings screen currently, however it just doesn't look professional enough and I would like something that looks more 'iOS'.
我一直在研究如何为我的应用程序创建一个看起来与 iOS 设置应用程序相同的设置屏幕,但是我找不到 iOS 7/8/Swift 版本。我目前有一个自定义设计的设置屏幕,但是它看起来不够专业,我想要看起来更“iOS”的东西。
Something like this would be perfect: http://jomnius.blogspot.co.uk/2011/04/easy-way-to-create-settings-view.htmlbut obviously this won't work now.
像这样的东西将是完美的:http: //jomnius.blogspot.co.uk/2011/04/easy-way-to-create-settings-view.html但显然这现在不起作用。
I was hoping someone could recommend a way that allows me to do something similar to this?
我希望有人可以推荐一种允许我做类似事情的方法?
采纳答案by Mike
Like 'Epic Byte' stated above, going with a UITableViewController with grouped style is an approach that ended up working for me. That tip put me down the right path.
就像上面提到的“Epic Byte”一样,使用具有分组样式的 UITableViewController 是一种最终对我有用的方法。这个提示让我走上了正确的道路。
Here are some links that helped me get the job done (in my case I also needed this to appear in a tab bar controller):
以下是一些帮助我完成工作的链接(在我的情况下,我还需要将其显示在标签栏控制器中):
- http://useyourloaf.com/blog/static-table-views-with-storyboards.html
- http://www.appcoda.com/storyboard-tutorial-create-tab-bar-controller-and-web-view/
- http://shrikar.com/xcode-6-tutorial-grouped-uitableview/
- http://useyourloaf.com/blog/static-table-views-with-storyboards.html
- http://www.appcoda.com/storyboard-tutorial-create-tab-bar-controller-and-web-view/
- http://shrikar.com/xcode-6-tutorial-grouped-uitableview/
Note that even though the screenshots appear to be for iOS versions < 8, the mechanics in the storyboard view carry over.
请注意,即使屏幕截图似乎适用于低于 8 的 iOS 版本,故事板视图中的机制仍然存在。
回答by Rom
The above answer is correct, but I wanted to add the solution itself here to save time for future users.
In order to make a regular UITableView look like the "Settings" page, you only need to to two things:
1. implement tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
and tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
so that the table will have multiple sections with headers.
2. set the table style
to .grouped
, which can be done via the storyboard editor.
上面的答案是正确的,但我想在这里添加解决方案本身,以节省未来用户的时间。
为了让一个普通的 UITableView 看起来像“设置”页面,你只需要做两件事:
1. 实现tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
并且tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?
让表格有多个带有标题的部分。
2. 将表格设置style
为.grouped
,这可以通过故事板编辑器完成。