Home > Net >  why is my UIButton in TitleView not working
why is my UIButton in TitleView not working

Time:11-25

I have a custom view containing an UIButton that I want to use as titleView:

let titleView = Bundle.main.loadNibNamed("TitleView", owner: self,
 options: nil)?[0] as? TitleView
titleView?.title.text = self.title        
navigationController?.navigationBar.topItem?.titleView = titleView

The button is linked with an IBAction in it's class. The View is displayed correctly in the navigation bar, but the button is not working. It doesn't even get highlighted during the touch. Looks like something is preventing the touch event.

screen

CodePudding user response:

Add the code below to your titleView

override var intrinsicContentSize: CGSize {
    return UIView.layoutFittingExpandedSize
}
  • Related