IOS core text计算文本高度及最大宽度
来源:互联网 发布:java获取局域网ip地址 编辑:程序博客网 时间:2024/05/21 09:09
转自:http://lists.apple.com/archives/quartz-dev/2008/Mar/msg00079.html
- (CGSize) measureFrame: (CTFrameRef) frame forContext: (CGContext *) cgContext
{//frame为排版后的文本
CGPathRefframePath =CTFrameGetPath(frame);
CGRectframeRect =CGPathGetBoundingBox(framePath);
CFArrayReflines =CTFrameGetLines(frame);
CFIndexnumLines =CFArrayGetCount(lines);
CGFloatmaxWidth =0;
CGFloattextHeight =0;
// Now run through each line determining the maximum width of all the lines.
// We special case the last line of text. While we've got it's descent handy,
// we'll use it to calculate the typographic height of the text as well.
CFIndexlastLineIndex = numLines -1;
for(CFIndexindex =0; index < numLines; index++)
{
CGFloatascent, descent, leading, width;
CTLineRefline = (CTLineRef)CFArrayGetValueAtIndex(lines, index);
width =CTLineGetTypographicBounds(line, &ascent, &descent, &leading);
if(width > maxWidth)
{
maxWidth = width;
}
if(index == lastLineIndex)
{
// Get the origin of the last line. We add the descent to this
// (below) to get the bottom edge of the last line of text.
CGPointlastLineOrigin;
CTFrameGetLineOrigins(frame,CFRangeMake(lastLineIndex,1), &lastLineOrigin);
// The height needed to draw the text is from the bottom of the last line
// to the top of the frame.
textHeight = CGRectGetMaxY(frameRect) - lastLineOrigin.y+ descent;
}
}
// For some text the exact typographic bounds is a fraction of a point too
// small to fit the text when it is put into a context. We go ahead and round
// the returned drawing area up to the nearest point. This takes care of the
// discrepencies.
returnCGSizeMake(ceil(maxWidth),ceil(textHeight));
}
- IOS core text计算文本高度及最大宽度
- iOS开发-计算label文本大小尺寸高度宽度
- [IOS 开发] NSString-计算文本的宽度和高度
- ios 动态计算文本的高度或宽度
- 获取Text文本的高度和宽度
- ios 计算 文本高度!
- iOS计算文本高度
- android 绘制计算text高度,宽度大小
- 如何使用Core Text计算一段文本绘制在屏幕上之后的高度
- 如何使用Core Text计算一段文本绘制在屏幕上之后的高度
- 如何使用Core Text计算一段文本绘制在屏幕上之后的高度
- 计算文本宽度和高度的方法
- swift js 计算文本物理宽度 高度
- 自定义分类计算文本高度和宽度
- IOS 获取文本的高度和宽度
- iOS 计算文本的高度
- iOS 动态计算文本高度
- iOS 计算文本的高度
- 使用Mybatis Generator自动生成Mybatis相关代码
- IOS UISlider来显示页数、页码提示
- Android 图形系统剖析
- linux驱动程序开发的简单休眠
- java堆和栈的区别
- IOS core text计算文本高度及最大宽度
- 【GOF设计模式之路】-- Singleton
- Linux/UNIX常用命令速查手册
- web开发必须要注意的
- IOS利用Core Text对文字进行排版
- linux使用 netlink 添加路由简单代码
- iPhone4S国行或春节前开售 联通蓄势待发
- first集,follow集,LL(1)分析表
- 地铁上的老人