2017-02-28 7 views
0

boundingRectWithSize를 사용하여 텍스트의 높이를 계산할 때 충돌이 발생합니다. 텍스트에 그림이 있기 때문에 어쩌면 찾을 수 있습니다. 누군가이 문제를 해결하는 방법을 알려줄 수 있습니다.boundingRectWithSize 이모티콘으로 인한 오류

CGFloat kScreenMargin = 15.; 
    CGFloat kScreenWidth = [UIScreen mainScreen].bounds.size.width; 

    self.content = @"Eefggg‍‍"; 

    CGFloat contentH = [self.content boundingRectWithSize:CGSizeMake(kScreenWidth - 2 * kScreenMargin, MAXFLOAT) 
                options:NSStringDrawingUsesLineFragmentOrigin 
               attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size.height; 

Here is the crash screenshot

답변

0

먼저 인코딩 문자열로 변환 한 후 높이를 얻을 :

CGFloat kScreenMargin = 15.; 
    CGFloat kScreenWidth = [UIScreen mainScreen].bounds.size.width; 
NSString *strEmo = @"Eefggg‍‍" 
NSData *data = [strEmo dataUsingEncoding:NSNonLossyASCIIStringEncoding]; 
NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
self.content = goodValue; 
CGFloat contentH = [self.content boundingRectWithSize:CGSizeMake(kScreenWidth - 2 * kScreenMargin, MAXFLOAT) 
                options:NSStringDrawingUsesLineFragmentOrigin 
               attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size.height; 
+0

중국어 작업을 수행하는 방법에 – iCloudy

+0

@iCloudy http://stackoverflow.com/questions/14619316/chiness을 -charecter-encoding-issue-iphone –