The first screen of my application is a UITableViewController without a navigation bar, which means that the content flows under the status bar so there's a lot of text collisions. I've adjusted both the properties for Under top bars and Adjust scroll view insets which do actually stop it from scrolling under, but at the cost of keeping the top of the table view under. I've attempted to set the UITableView frame to offset by 20 pixels, but it doesn't appear to take effect and as I currently need the app to be compatible with iOS 6 I can't jump to iOS 7 Storyboards to force autolayout to use the top height guide. Has anyone found a solution that works for both versions?

我尝试过的事情:设置edgesForExtendedLayout,在Storyboard中更改顶部栏下的设置和调整滚动视图,迫使框架到一个新的区域。

一图胜千言万语:


当前回答

我这样做的视网膜/非视网膜显示

BOOL isRetina = FALSE;

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
    if ([[UIScreen mainScreen] scale] == 2.0) {
        isRetina = TRUE;
    } else {
        isRetina = FALSE;
    }
}

if (isRetina) {
    self.edgesForExtendedLayout=UIRectEdgeNone;
    self.extendedLayoutIncludesOpaqueBars=NO;
    self.automaticallyAdjustsScrollViewInsets=NO;
}

其他回答

适用于swift 3 - In viewDidLoad();

let statusBarHeight = UIApplication.shared.statusBarFrame.height

let insets = UIEdgeInsets(top: statusBarHeight, left: 0, bottom: 0, right: 0)
tableView.contentInset = insets
tableView.scrollIndicatorInsets = insets

这段代码: 1. 获取状态栏的高度 2. 为表视图的顶部提供一个与状态栏高度相等的内容插入。 3.为滚动指示器提供相同的插入,因此它出现在状态栏的下方。

这是一个Swift 2.3。(Xcode 8.0)解决方案。我已经创建了UITableView的子类。

class MYCustomTableView: UITableView
{   
    override func drawRect(rect: CGRect) {
        super.drawRect(rect)
        contentInset    = UIEdgeInsetsZero
    }
}

内容插入应该始终为零(默认情况下)。我手动设置为零。你也可以添加一个check方法来检查,如果它不是你想要的,只要得到正确的rect就可以了。这个变化只会在tableview被绘制时反映出来(这并不经常发生)。

不要忘记在你的IB中更新TableView(在TableViewController中或只是在你的ViewController中的TableView中)。

这是用Swift写的 调整@lipka的回答:

tableView.contentInset = UIEdgeInsetsMake(20.0, 0.0, 0.0, 0.0)

如果你用编程的方式做事情,并且使用一个没有UINavigationController的UITableViewController,你最好的选择是在viewDidLoad中做以下事情:

斯威夫特3

self.tableView.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)

早些时候,迅速

self.tableView.contentInset = UIEdgeInsetsMake(20.0f, 0.0f, 0.0f, 0.0f);

UITableViewController仍然会滚动到状态栏后面,但当滚动到顶部时,不会在状态栏下面。

我把它的工作大小设置为自由形式