Check if there is an emoji contained in a string

后端 未结 11 1252
野的像风
野的像风 2020-12-31 11:49

I am getting the text size of a string with this

textSize = [[tempDict valueForKeyPath:@\"caption.text\"] sizeWithFont:[UIFont systemFontOfSize:12] constrain         


        
11条回答
  •  青春惊慌失措
    2020-12-31 12:23

    Please, see this answer How to get NSString size when NSString includes emojis?

    If you have only emojis then you shouldn't use sizeWithFont. Use label for it or something else.

    NSString doesn't work with Emojis, only text. If you have emojis, then you should use [label sizeToFit] or [label sizeThatFits:]

    Also, you can use this code:

     id text = [tempDict valueForKeyPath:@"caption.text"]
    
     if (![text isKindOfClass:[NSNull class]]) {
     ...
     }
    

    Because, you get NSNull from dictionary, but it doesn't equal nil, and your condition works.

提交回复
热议问题