iOS 11 navigationItem.titleView Width Not Set

后端 未结 14 1733
遥遥无期
遥遥无期 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:43

    You can also use constraints if you don't want to override intrinsicContentSize. Here's a demo of SnapKit

    self.navigationItem.titleView = titleView
    if #available(iOS 11, *) {
        titleView.snp.makeConstraints({ (make) in
            make.width.equalTo(250) // fixed width
            make.height.equalTo(30) // less than 44(height of naviagtion bar)
        })
    }else {
        titleView.frame = ...
    }
    

    But if there are more than one navigationbaritems on any side(left or right) navigationbar, you should use intrinsicContentSize;

提交回复
热议问题