iOS 9 UITableView cell's text label not the full width of the UITableView

后端 未结 2 1005
猫巷女王i
猫巷女王i 2021-02-07 10:24

Since updating to iOS 9, table view cell\'s in iPad landscape no longer stretch the full width of the table in my unit tests.

My test is a simple table that takes a snap

相关标签:
2条回答
  • 2021-02-07 10:53

    When I tested my App with iOS9, I noticed huge margins, on some UITableViews, both left and right. After a bit of investigation, I found the following new method:

    // iOS9
    if([self.tableView respondsToSelector:@selector(setCellLayoutMarginsFollowReadableWidth:)]) {
        self.tableView.cellLayoutMarginsFollowReadableWidth = NO;
    }
    

    When the above code is called, after instantiating your UITableView, it should remove them.

    Paste this code after you set your tableView delegate.

    Hope it helps.

    0 讨论(0)
  • 2021-02-07 10:55

    hope this help you

        //    MARK: - TableView Delegates And Datasource Method -
    
    func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
        // IOS 7
        if(self.respondsToSelector(Selector("setSeparatorInset:"))){
            self.separatorInset = UIEdgeInsetsZero
            cell.separatorInset = UIEdgeInsetsZero
            tableView.separatorInset = UIEdgeInsetsZero;
        }
        // OTHER
        if(self.respondsToSelector(Selector("setPreservesSuperviewLayoutMargins:"))){
            if #available(iOS 8.0, *) {
                self.separatorInset = UIEdgeInsetsZero
                cell.layoutMargins = UIEdgeInsetsZero;
                cell.preservesSuperviewLayoutMargins = false
            }
        }
    
        // iOS 8
        if(self.respondsToSelector(Selector("setLayoutMargins:"))){
            if #available(iOS 8.0, *) {
                self.separatorInset = UIEdgeInsetsZero
                cell.layoutMargins = UIEdgeInsetsZero
            }
        }
        // iOS 9
        if (self.respondsToSelector("setCellLayoutMarginsFollowReadableWidth:")){
            if #available(iOS 9.0, *) {
                self.cellLayoutMarginsFollowReadableWidth = false
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题