I am getting the text size of a string with this
textSize = [[tempDict valueForKeyPath:@\"caption.text\"] sizeWithFont:[UIFont systemFontOfSize:12] constrain
Now with the new release of iOS 10, for the following emojis it doesn't work:
Emojis
The following code snippet is tried and tested for both iOS 9 and iOS 10:
extension String {
var containsEmoji: Bool {
for scalar in unicodeScalars {
switch scalar.value {
case 0x1F600...0x1F64F, // Emoticons
0x1F300...0x1F5FF, // Misc Symbols and Pictographs
0x1F680...0x1F6FF, // Transport and Map
0x2600...0x26FF, // Misc symbols
0x2700...0x27BF, // Dingbats
0xFE00...0xFE0F, // Variation Selectors
0x1F910...0x1F918, // New Emoticons
0x1F1E6...0x1F1FF, // Flags
0x1F980...0x1F984,
0x1F191...0x1F19A,
0x1F201...0x1F202,
0x1F232...0x1F23A,
0x1F250...0x1F251,
0x23E9...0x23F3,
0x23F8...0x23FA,
0x1F170...0x1F171,
0x1F17E,
0xA9,
0xAE,
0x2122,
0x2328,
0x3030,
0x1F0CF,
0x1F18E,
0x1F9C0:
return true
default:
continue
}
}
return false
}
}
Create a String extension in your app as mentioned above.
And can be used like this:
if string.containsEmoji {
// Do operations here
}