getAttributedStringHeightWithString
来源:互联网 发布:小gps数据导不出 编辑:程序博客网 时间:2024/06/03 08:59
- - (int)getAttributedStringHeightWithString:(NSAttributedString *) string WidthValue:(int) width
- {
- int total_height = 0;
- CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)string); //string 为要计算高度的NSAttributedString
- CGRect drawingRect = CGRectMake(0, 0, width, 1000); //这里的高要设置足够大
- CGMutablePathRef path = CGPathCreateMutable();
- CGPathAddRect(path, NULL, drawingRect);
- CTFrameRef textFrame = CTFramesetterCreateFrame(framesetter,CFRangeMake(0,0), path, NULL);
- CGPathRelease(path);
- CFRelease(framesetter);
- NSArray *linesArray = (NSArray *) CTFrameGetLines(textFrame);
- CGPoint origins[[linesArray count]];
- CTFrameGetLineOrigins(textFrame, CFRangeMake(0, 0), origins);
- int line_y = (int) origins[[linesArray count] -1].y; //最后一行line的原点y坐标
- CGFloat ascent;
- CGFloat descent;
- CGFloat leading;
- CTLineRef line = (CTLineRef) [linesArray objectAtIndex:[linesArray count]-1];
- CTLineGetTypographicBounds(line, &ascent, &descent, &leading);
- total_height = 1000 - line_y + (int) descent +1; //+1为了纠正descent转换成int小数点后舍去的值
- CFRelease(textFrame);
- return total_height;
- }
0 0
- getAttributedStringHeightWithString
- C++ - 容器(container)的erase()函数
- 英语学习一些有用的东东
- CentOS 5开启telnet服务和一些基本配置
- html的ul和li标签
- Environment variable: "PATH" - This test checks whether the length of the environment variable "PATH
- getAttributedStringHeightWithString
- What are some lesser known but useful Unix commands?
- cocos2d-x动画加速与减速
- 统计
- HDFS——如何获取文件的属性信息
- 使用vs2010编译项目时出现COFF错误的解决方案
- HDU1026
- Linux下查看.so和可执行文件是否debug编译
- 一般数据库增量更新方法--假增量