Dismiss iOS Keyboard With Any UIButton

I was messing around yesterday making a simple iOS practice app and I ran into issue where a UIButton was visible above a text field so I wanted the keyboard to be dismissed if the user hit that button while editing. Turns out it is stupid simple, all you have to do is have the UITextField resign as the first responder when the UIButton is pressed.

I added the line [myTextField resignFirstResponder]; to the UIButton’s IBAction method and that’s it, the keyboard is now dismissed when a user hits the UIButton.