iOS 8 UITableView separator inset 0 not working

前端 未结 30 1770
清酒与你
清酒与你 2020-11-22 14:38

I have an app where the UITableView\'s separator inset is set to custom values - Right 0, Left 0. This works perfectly in iOS 7.

30条回答
  •  轮回少年
    2020-11-22 15:00

    Here's an easy way to globally remove the inset.

    In UITableViewCell+Extensions.swift:

    import UIKit
    
    extension UITableViewCell {
    
      override public var layoutMargins: UIEdgeInsets {
        get { return UIEdgeInsetsZero }
        set { }
      }
    
    }
    

    In AppDelegate application:didFinishLaunchingWithOptions::

      UITableViewCell.appearance().separatorInset = UIEdgeInsetsZero
    

    You might think to a) also just override separatorInset in the extension, or b) set the appearance proxy for layoutMargins, instead. Neither will work. Even though separatorInset is indicated to be a property, attempting to override it as a property (or method) generates compiler errors. And setting the appearance proxy for UITableViewCell's layoutMargins (or, for that matter, also setting the appearance proxies for UITableView's layoutMargins and separatorInset) has no effect.

提交回复
热议问题