Skip to content

Instantly share code, notes, and snippets.

View gleue's full-sized avatar

Tim Gleue gleue

View GitHub Profile
@gleue
gleue / UITextFieldDelegate.m
Last active January 5, 2022 03:41
Force input into UITextField to uppercase
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
// Inspiration: http://stackoverflow.com/a/6265614 and http://stackoverflow.com/a/13388037
//
// Check if the added string contains lowercase characters.
// If so, those characters are replaced by uppercase characters.
//
NSRange lowercaseCharRange = [string rangeOfCharacterFromSet:[NSCharacterSet lowercaseLetterCharacterSet]];
if (lowercaseCharRange.location != NSNotFound) {