- (int)getAttributedStringHeightWithString:(NSAttributedString *)  string  WidthValue:(int) width
{
int total_height = ; CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)string); //string 为要计算高度的NSAttributedString
CGRect drawingRect = CGRectMake(, , width, ); //这里的高要设置足够大
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, drawingRect);
CTFrameRef textFrame = CTFramesetterCreateFrame(framesetter,CFRangeMake(,), path, NULL);
CGPathRelease(path);
CFRelease(framesetter); NSArray *linesArray = (NSArray *) CTFrameGetLines(textFrame); CGPoint origins[[linesArray count]];
CTFrameGetLineOrigins(textFrame, CFRangeMake(, ), origins); int line_y = (int) origins[[linesArray count] -].y; //最后一行line的原点y坐标 CGFloat ascent;
CGFloat descent;
CGFloat leading; CTLineRef line = (CTLineRef) [linesArray objectAtIndex:[linesArray count]-];
CTLineGetTypographicBounds(line, &ascent, &descent, &leading); total_height = - line_y + (int) descent +; //+1为了纠正descent转换成int小数点后舍去的值 CFRelease(textFrame); return total_height; }

来自:http://blog.csdn.net/iunion/article/details/7925951

准确计算CoreText高度的方法:的更多相关文章

  1. 30、准确计算CoreText高度的方法

    http://ios-iphone.diandian.com/post/2012-03-29/18389515 - (int)getAttributedStringHeightWithString:( ...

  2. iOS开发 准确计算Coretext高度

    - (int)getAttributedStringHeightWithString:(NSAttributedString *)  string  WidthValue:(int) width{   ...

  3. IOS8 不用计算Cell高度的TableView实现方案

    这个新特性,意味着View被Autolayout调整frame后,会自动拉伸和收缩SupView. 具体到Cell,要求cell.contentView的四条边都与内部元素有约束关系. 在TableV ...

  4. js中获取窗口高度的方法

    取窗口滚动条滚动高度 function getScrollTop() { var scrollTop=0; if(document.documentElement&&document. ...

  5. 动态计算UITableViewCell高度

    动态计算UITableViewCell高度 UILabel in UITableViewCell Auto Layout - UILabel的属性Lines设为了0表示显示多行.Auto Layout ...

  6. ios 根据文字数量计算UILabel高度(已修改)

    由于留言的朋友给出了更好的方法,所以下面的代码都是它留言中给出的,优于我前面计算Lable高度方法,这个可以说非常的准,是IOS自带的计算UILABEL高度的方式. 一.实现代码 // 创建label ...

  7. iOS依据字符串计算UITextView高度

    iOS计算字符串高度,有须要的朋友能够參考下. 方法一:ios7.0之前适用 /** @method 获取指定宽度width,字体大小fontSize,字符串value的高度 @param value ...

  8. 【九天教您南方cass 9.1】 10 DTM土方计算的四种方法

    同学们大家好,欢迎收看由老王测量上班记出品的cass9.1视频课程 我是本节课主讲老师九天. 我们讲课的教程附件也是共享的,请注意索取测量空间中. [点击索取cass教程]5元立得 (给客服说暗号:“ ...

  9. 转:动态计算UITableViewCell高度详解

    转自:http://www.cocoachina.com/industry/20140604/8668.html   不知道大家有没有发现,在iOS APP开发过程中,UITableView是我们显示 ...

随机推荐

  1. [Bash] Move and Copy Files and Folders with Bash

    In this lesson we’ll learn how to move and rename files (mv) and copy (cp) them. Move index.html to ...

  2. InnoDB: Error: io_setup() failed with EAGAIN after 5 attempts

    在一台server中以各数据库的备份文件为数据文件启动多个MySQL实例供SQL Review使用. 之前执行一直没有问题(最多的时候有23个MySQL实例同一时候执行).后来新配置了一台server ...

  3. exadata(ilom) 练习

    Oracle(R) Integrated Lights Out Manager Version 3.0.16.10 r65138 Copyright (c) 2011, Oracle and/or i ...

  4. 修改linux环境变量配置文件

    发现error ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost) ...

  5. 硬件开发之pcb---PCB抗干扰设计原则

    一 电源线布置: 1.电源线.地线的走向应与资料的传递方向一致. 二 地线布置: 1.数字地与模拟地分开. 2.接地线应尽量加粗,致少能通过3倍于印制板上的允许电流,一般应达2~3mm. 3.接地线应 ...

  6. 2016/04/18 session cookie 对比 应用 <?php session_start() / setcookie()?>

    ①会话 huihua.php <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...

  7. Element is not clickable at point SeleniumWebdriverException

    Element is not clickable at point SeleniumWebdriverException | Selenium Easy http://www.seleniumeasy ...

  8. “Invalid configuration file. File "I:/My Virtual Machines/Windows XP english Professional/Windows XP Professional.vmx" was created by a VMware product

    “Invalid configuration file. File "I:/My Virtual Machines/Windows XP english Professional/Windo ...

  9. ZOJ1610 Count the Colors —— 线段树 区间染色

    题目链接:https://vjudge.net/problem/ZOJ-1610 Painting some colored segments on a line, some previously p ...

  10. YTU 1098: The 3n + 1 problem

    1098: The 3n + 1 problem 时间限制: 1 Sec  内存限制: 64 MB 提交: 368  解决: 148 题目描述 Consider the following algor ...