我想更改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
}
}