How can I get a full-sized UINavigationBar titleView

前端 未结 6 1569
遇见更好的自我
遇见更好的自我 2020-12-25 14:25

I am trying to add a custom control as the titleView in a UINavigationBar. When I do so, despite setting the frame and the properties that would normally assume full width,

6条回答
  •  长发绾君心
    2020-12-25 14:49

    Swift version of ksm's answer

    let leftOffset: CGFloat = 60
    let rightOffset: CGFloat = 60
    
    @objc override var frame: CGRect {
         didSet {
                    let width: CGFloat = UIScreen.main.bounds.width - leftOffset - rightOffset
                    let height: CGFloat = 44
    
                    super.frame = CGRect(
                        x: leftOffset,
                        y: 20,
                        width: width,
                        height: height
                    )
           }
    }
    

提交回复
热议问题