How to place a button to the center of navigation bar?

Viewed 34

I am trying to place a clickable info button showing a message and body close to the navigation title name. I have created a function that will show the message however it isnt place on the center of the navigation controller. How do I fixed this ?
enter image description here

func tooltip(body: String, title: String, titleSize: CGFloat, bodySize: CGFloat) {
    let alertController = UIAlertController(title: title,message: body, preferredStyle: .actionSheet)
    let titleAttributes = [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: titleSize)]
    let titleString = NSAttributedString(string: title, attributes: titleAttributes)
    let messageAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: bodySize)]
    let messageString = NSAttributedString(string: body, attributes: messageAttributes)
   
    alertController.setValue(titleString, forKey: "attributedTitle")
    alertController.setValue(messageString, forKey: "attributedMessage")
    
    let popover = alertController.popoverPresentationController
    popover?.sourceView = self.view
    
    let button = UIButton()
    button.setImage(UIImage(systemName: "info.circle"), for: .normal)
    button.center = self.view.center
    popover?.sourceRect = button.frame
    popover?.permittedArrowDirections = .any

    self.present(alertController, animated: true, completion: nil)
}

private func setupNavigationItem() {
     self.title = self.viewModel.filter.label
     
     switch title {
        case "Last Visit":
         tooltip(body: """
                        XXXX \n
                        XXXX \n
                        XXXX \n
                        XXXX \n
                        XXXX \n
                        XXXX \n
                        XXXX"\n
                        """,
       title: "The Last Visit filter includes:", titleSize: 14.0, bodySize: 15.0)
        default:
            break
     }
    
     navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(donePressed))
 }
0 Answers
Related