3

I am setting titleView using this method

func addConstrainstToSearchField(with size: CGSize? = nil) {
        var width : CGFloat = 0.0
        if let searchField = self.searchfield {
            var frame = searchField.frame
            if size != nil, let frameWidth = size?.width {
                width = frameWidth
            } else if let frameWidth = self.navigationController?.navigationBar.frame.size.width {
                width = frameWidth
            }
            frame.size.width = (width - 145.0) * 0.90 // 136 is width of (left and right BarButtonItems) button
            searchField.frame = frame
            self.navigationItem.titleView = searchField
//            DispatchQueue.main.async(execute: {
//                self.navigationItem.titleViewWithConstraint = searchField
//            })
        }
    }

and I am calling this method from viewdidload and viewWillTransiion

but it's not showing properly

screenshot In landscape

image 2

thanks in advance

Nagar
  • 73
  • 1
  • 7

0 Answers0