iOS 11 navigationItem.titleView Width Not Set

后端 未结 14 1720
遥遥无期
遥遥无期 2020-12-13 07:58

Seeing a behavior on iOS11 with a navigationItem.titleView where the width of the titleView is not the full width of the screen.

I have a custom view that I set as t

14条回答
  •  [愿得一人]
    2020-12-13 08:37

    This class will do the trick. Make sure you set your custom view's class to this one:

    import UIKit
    
    class TitleView: UIView {
    
        override init(frame: CGRect) {
            super.init(frame: frame)
            translatesAutoresizingMaskIntoConstraints = false
        }
    
        required init?(coder: NSCoder) {
            super.init(coder: coder)
            translatesAutoresizingMaskIntoConstraints = false
        }
    
        override var intrinsicContentSize: CGSize {
            CGSize(width: UIView.layoutFittingExpandedSize.width, height: self.bounds.height)
        }
    
    }
    

提交回复
热议问题