I am getting the text size of a string with this
textSize = [[tempDict valueForKeyPath:@"caption.text"] sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(280, CGFLOAT_MAX) lineBreakMode: NSLineBreakByWordWrapping];
The only problem I have is that if the string only contains an emoji, my app crashes. Is there an easy way to check for emojis or do I have to create an array with all possible emojis and then check for them using that?
error:
-[NSNull sizeWithFont:constrainedToSize:lineBreakMode:]: unrecognized selector sent to instance 0x3aa88a60
if ([tempDict valueForKeyPath:@"caption.text"]){
NSLog(@"%@", [tempDict valueForKeyPath:@"caption"]);
//Measure the message label box height
textSize = [[tempDict valueForKeyPath:@"caption.text"] sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(280, CGFLOAT_MAX) lineBreakMode: NSLineBreakByWordWrapping];
int height = 320 + 20 + textSize.height;
[cellHeight addObject:[NSNumber numberWithInt:height]];
}
it's too late reply into this but it's may help someone.
@Simha.IC answer is great.
However it does not work with the new iOS 9.1 emojis'.
Simha.IC snippet is not detecting these ones:
Simple Swift solution with checking every scalar in unicodeScalars are in the set CharacterSet.symbols
But I found some emoji 1.0 items like ℹ️ is not classify as an emoji. So I create this checker:
And this is the checker which can detect ℹ️:
You can use this new framework
https://github.com/woxtu/NSString-RemoveEmoji
Usage:
This issue may occur if there are any characters past
0x00ff
. In other words, there are many Unicode characters in addition to Emoji that you may need to account for. In order to see if there are any Unicode characters (beyond the boundary of extended ASCII) use the following.