I have placed UIButton to right view of textfield. But I see the below warning
My code for UIButton:
private lazy var myButton : UIButton = {
let button = UIButton()
var config = UIButton.Configuration.plain()
config.contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 16)
button.configuration = config
button.frame = CGRect(x: CGFloat(myTextfield.frame.size.width - 16), y:(myTextfield.frame.size.height - 16) / 2, width: CGFloat(40), height: CGFloat(30))
button.contentMode = .scaleAspectFit
button.backgroundColor = .clear
button.translatesAutoresizingMaskIntoConstraints = false
button.setImage(passwordButtonImage, for: .normal)
button.addTarget(self, action: #selector(self.toggle(_:)), for: .touchUpInside)
return button
}()
code for adding it to textfield:
@IBOutlet private weak var mytextField: UITextField {
didSet {
mytextField.rightView = myButton
mytextField.rightViewMode = .always
}
}
Removing translatesAutoresizingMaskIntoConstraints to false solved my issue. As I am not giving any constraints manually I don't need this.