First I think that there are unneeded constraints on the text field:
- "Trailing Space to: End Date" is duplicated.
- If you are setting constraints for leading and trailing, there is no need to add another constraint for the width "Equal Width to: End Date".
- Same logic as above, since you are already added a fixed height constraint, there is no need to add "Equal Height to: End Date".
So, after fixing (removing the extra constraints), what you should do is to add IBOutlets in the view controller for the leading and the trailing constraints, then you can edit their constant
value to 0.0.
class ViewController: UIViewController {
//...
@IBOutlet weak var dateTextFieldLeading: NSLayoutConstraint!
@IBOutlet weak var dateTextFieldTrailing: NSLayoutConstraint!
// call this method when needed
func expandDateTextFieldWidth() {
dateTextFieldLeading.constant = 0.0
dateTextFieldTrailing.constant = 0.0
}
//...
}