效果
image.pngclass TextTitleView: UIView {
@IBOutlet weak var lbTitle: UILabel!
@IBOutlet weak var lbSubTitle: UILabel!
/*
navigationItem.titleView适配,不会挤到中间 iOS11之前默认不开启自动布局,
iOS11之后模块打开了,所以原来用frame做的自定义view,需要实现intrinsicContentSize方法,
但是2边还是有点间隙,可以设置偏移达到效果
*/
override var intrinsicContentSize: CGSize {
return UIView.layoutFittingExpandedSize
}
}
vc中调用
fileprivate func setupTitleView() {
vTitle.frame = CGRect(x: 0, y: 0, width: kScreenW, height: kNavBarH)
vTitle.configTitleView(title: bodyName, subTitle: tagName)
navigationItem.titleView = vTitle
}
网友评论