在我的UITableViewController中滚动几个项目会使单元格出现在我的UIStatusBar后面。我试着使用这个方法做一个变通的工作:
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中
有什么想法吗?
发布于 2016-09-26 17:51:22
一种方法是,重构UITableViewController并将其设置为UITableView,然后在状态栏下面添加一个顶部约束。
另一种方法是更改状态栏颜色,如下所示:
func setStatusBarBackgroundColor(color: UIColor) {
if let statusBar = UIApplication.sharedApplication().valueForKey("statusBarWindow")?.valueForKey("statusBar") as? UIView {
statusBar.backgroundColor = color
}
}但要小心,因为它是一个私有api。你的应用程序可能会被拒绝。
发布于 2016-09-26 18:39:01
根据您的用途,您可以只隐藏状态栏。
override var prefersStatusBarHidden: Bool {
return true
}发布于 2016-09-26 18:38:20
终于找到了答案:
创建自定义UIView并将其添加到navigationController的视图中
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)就像一种护身符。
https://stackoverflow.com/questions/39699404
复制相似问题