也许您可以使用该功能:
func setupNavUI() {
let addressTextField = UITextField(frame: CGRect(x: 0.0, y: 0.0, width: self.navigationItem.titleView?.frame.width ?? 100.0, height: 50.0))
addressTextField.rightViewMode = .always
let icon = FAKFontAwesome.sortDownIcon(withSize: 20.0)
icon?.setAttributes([NSAttributedString.Key.foregroundColor : UIColor.lightGray])
let image = icon?.image(with: CGSize(width: 20.0, height: 20.0))
let imageView = UIImageView(frame: CGRect(x: 0.0, y: 0.0, width: 20.0, height: 20.0))
imageView.image = image
let rightView = UIView(frame: CGRect(x: 0, y: 0, width: 20.0, height: 26.0))
rightView.addSubview(imageView)
addressTextField.rightView = rightView
addressTextField.placeholder = "Buscar una dirección"
self.navigationItem.titleView = addressTextField
}
此致