NSString *text = @"这里要很多字符,我就不打了……";
NSAttributedString *attributeString = [[NSAttributedString alloc] initWithString:text attributes:attributes];
NSRange range = NSMakeRange(0, attributeString.length);
NSDictionary *dict = [attributeString attributesAtIndex:0 effectiveRange:&range];
CGSize textSize = [text boundingRectWithSize:_contentTextView.bounds.size options:NSStringDrawingUsesLineFragmentOrigin| NSStringDrawingUsesFontLeading attributes:dict context:nil].size;
NSLog(@"height ----> %f,width ----> %f", textSize.height, textSize.width);
iOS:(boundingRectWithSize)按大小计算字符串高度
最新推荐文章于 2024-10-16 17:38:21 发布