- (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. org.hibernate.AnnotationException: No identifier specified for entity:

    使用hibernate的e-r映射pojo类的时候遇到org.hibernate.AnnotationException: No identifier specified for entity的异常, ...

  2. 蚂蜂窝VS穷游最世界-自由行类App分析

    很多其它内容请关注博客: http://www.china10s.com/blog/? p=150 一.产品概述 体验环境: 机型:iPhone 6 型号:64G版 系统:iOS9.2 蚂蜂窝APP版 ...

  3. 选带傅里叶变换(zoom-fft)

    选带傅里叶变换的原理大家能够看书.大致的步骤为 移频 (将选带的中心频率移动到零频) 数字低通滤波器  (防止频率混叠) 又一次採样  (将採样的数据再次间隔採样,间隔的数据取决于分析的带宽,就是放大 ...

  4. Asp.net MVC 简单分页 自做简单分页

    Asp.net MVC 简单分页:   public static string Pager(int page,int pageSize,int total)         {           ...

  5. FancyCoverFlow

    https://github.com/davidschreiber/FancyCoverFlow

  6. 实现@using{}代码块

    前几天,我要写个插件,放在asp.net mvc的view上.这需要写一些扩展HtmlHelper功能的方法.这些方法的一个参数是一段javascript代码. 假如这个参数类型是字符型,当然很简单了 ...

  7. V4L学习

    http://blog.csdn.net/wangrunmin/article/details/7764768# http://blog.sina.com.cn/s/blog_a44175a90101 ...

  8. Lightoj 1009 - Back to Underworld

    1009 - Back to Underworld    PDF (English) Statistics Forum Time Limit: 4 second(s) Memory Limit: 32 ...

  9. git lfs

    https://git-lfs.github.com/ 1.从这个网址下载git-lfs-windows-amd64-1.1.0.exe,运行这个安装包 2.然后打开git bash 输入git lf ...

  10. bootstrap3.0学习笔记记录1

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...