I use actually this code (set maximum 4 characters) :
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSUInteger newLength = [self.messageText.text length] + [string length] - range.length;
return (newLength > 4) ? NO : YES;
}
But emoji are considered like 2 characters.
How can I set the maximum amount of characters in a UITextField that contains emoji and text ?