首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableViewController和UIStatusbar

UITableViewController和UIStatusbar
EN

Stack Overflow用户
提问于 2016-09-26 17:39:20
回答 3查看 109关注 0票数 0

在我的UITableViewController中滚动几个项目会使单元格出现在我的UIStatusBar后面。我试着使用这个方法做一个变通的工作:

代码语言:javascript
复制
var bounds = self.view.bounds
    bounds.origin.y -= 20.0;
    self.view.bounds = bounds
    // Create a solid color background for the status bar



    let statusFrame = CGRect(x: 0, y: -20, width: bounds.size.width, height: 20)
    let statusBar = UIView(frame: statusFrame)
    statusBar.backgroundColor = UIColor.red
    self.view.addSubview(statusBar)

这会在滚动前给我一个红色的条。稍微滚动一下,它就会消失。我还尝试将tableView的contentInset设置为UIApplication.shared.statusBarFrame.height,但也是这样做的。

保留导航栏很重要。另外,我的TableViewController嵌入在UINavigationController

有什么想法吗?

EN

回答 3

Stack Overflow用户

发布于 2016-09-26 17:51:22

一种方法是,重构UITableViewController并将其设置为UITableView,然后在状态栏下面添加一个顶部约束。

另一种方法是更改状态栏颜色,如下所示:

代码语言:javascript
复制
func setStatusBarBackgroundColor(color: UIColor) {
    if let statusBar = UIApplication.sharedApplication().valueForKey("statusBarWindow")?.valueForKey("statusBar") as? UIView {
        statusBar.backgroundColor = color
    }
}

但要小心,因为它是一个私有api。你的应用程序可能会被拒绝。

票数 1
EN

Stack Overflow用户

发布于 2016-09-26 18:39:01

根据您的用途,您可以只隐藏状态栏。

代码语言:javascript
复制
override var prefersStatusBarHidden: Bool {
    return true
}
票数 1
EN

Stack Overflow用户

发布于 2016-09-26 18:38:20

终于找到了答案:

创建自定义UIView并将其添加到navigationController的视图中

代码语言:javascript
复制
    let rect = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width,
    height: UIApplication.shared.statusBarFrame.height)

    let bar = UIView(frame: rect)
    bar.backgroundColor = UIColor.white

    navigationController?.view.addSubview(bar)

就像一种护身符。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39699404

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档