美文网首页
swift 设置titleView居中

swift 设置titleView居中

作者: 喵喵粉 | 来源:发表于2020-09-16 21:20 被阅读0次

效果

image.png
class 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
}

相关文章

网友评论

      本文标题:swift 设置titleView居中

      本文链接:https://www.haomeiwen.com/subject/kdohyktx.html