如何更改UISearchBar cancelButton的宽度?

时间:2019-12-30 09:45:31

标签: autolayout uisearchbar swift4.2

我想更改uisearchbar中的cancelButton的宽度。代码在下面,但不受影响。有人可以帮我吗?

 override func layoutSubviews() {
    super.layoutSubviews()
    if fullRoundedTextField {
        let textField = self.value(forKey: "searchField") as! UITextField
        textField.layer.cornerRadius = textField.bounds.height * 0.5
        textField.layer.masksToBounds = true
    }

    if let cancelButton = self.value(forKey: "cancelButton") as? UIButton {
         cancelButton.widthAnchor.constraint(equalToConstant: 150).isActive = true
    }
}

0 个答案:

没有答案
相关问题