+ (CGSize)boundingALLRectWithSize:(NSString *)txt Font:(UIFont *)font Size:(CGSize)size {
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:txt];
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
[style setLineSpacing:2.0f];//切记LineSapcing >= 2,不然会显示不全
[attributedString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(, [txt length])]; CGSize realSize = CGSizeZero; #if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
CGRect textRect = [txt boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font, NSParagraphStyleAttributeName:style} context:nil];
realSize = textRect.size;
#else
realSize = [txt sizeWithFont:font constrainedToSize:size];
#endif realSize.width = ceilf(realSize.width);
realSize.height = ceilf(realSize.height);
return realSize;
}
调用:float strHeight = [Util boundingALLRectWithSize:str Font:[UIFont systemFontOfSize:] Size:CGSizeMake(SCREEN_WIDTH-, MAXFLOAT)].height;

 

iOS之动态计算文字的高度的更多相关文章

  1. iOS中动态计算不同颜色、字体的文字高度

    在改项目bug的时候,有一个问题动态计算label的高度,前开发者竟然用字符串长度除以14.16这样的常量来计算是否换行,结果cell的高度问题非常严重. 因为label内容里有部分关键字是要另一种颜 ...

  2. iOS开发总结-UITableView 自定义cell和动态计算cell的高度

    UITableView cell自定义头文件:shopCell.h#import <UIKit/UIKit.h>@interface shopCell : UITableViewCell@ ...

  3. iOS学习之根据文本内容动态计算文本框高度的步骤

    在视图加载的过程中,是先计算出frame,再根据frame加载视图的,所以在设计计算高度的方法的时候,设计成加号方法; //首先给外界提供计算cell高度的方法 + (CGFloat)heightFo ...

  4. IOS7中动态计算UILable的高度

    .h文件 #import <UIKit/UIKit.h> @interface UILabel (ContentSize) - (CGSize)contentSize; @end .m文件 ...

  5. iOS开发之计算文字尺寸

    /** *  计算文字尺寸 * *  @param text    需要计算尺寸的文字 *  @param font    文字的字体 *  @param maxSize 文字的最大尺寸 */ - ( ...

  6. iOS实现页面既显示WebView,WebView下显示TableView,动态计算WebView内容高度

    实现效果如下: 忽略底部的评论视图,太丑了,待完善...... 实现思路: 1>页面布局采用TableView实现,顶部"关注"模块的View是TableView的table ...

  7. css3动态计算元素的高度及宽度

    1.px     像素,我们在网页布局中一般都是用px. 2.百分比     百分比一般宽泛的讲是相对于父元素,自适应网页布局越来越多,百分比也经常用到了 3.Viewport 当已知一个div的高度 ...

  8. 计算文字的高度和宽度--以微博会话界面中用户名(userName)为例

    所用方法 // NOTE: All of the following methods will default to drawing on a baseline, limiting drawing t ...

  9. iOS 动态计算文本内容的高度

    关于ios 下动态计算文本内容的高度,经过查阅和网上搜素,现在看到的有以下几种方法: 1. //  获取字符串的大小  ios6 - (CGSize)getStringRect_:(NSString* ...

随机推荐

  1. csharp:Optical Character Recognition

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...

  2. python全栈开发之路

    一.Python基础 python简介 python数据类型(数字\字符串\列表) python数据类型(元组\字典) python数据类型(集合) python占位符%s,%d,%r,%f prin ...

  3. Hello Activemq

    0. 如果永远是localhost 可能一直low下去 1.下载安装 activemq 1.1 从官网下载activemq.tar.gz 并上传(rz)到linux系统 并解压 tar zxvf /* ...

  4. 广告点击率预测(CTR) —— 在线学习算法FTRL的应用

    FTRL由google工程师提出,在13的paper中给出了伪代码和实现细节,paper地址:http://www.eecs.tufts.edu/~dsculley/papers/ad-click-p ...

  5. Java 之初(1)

    省赛结束之后有相当长一段空闲时间,于是就想先提前自学一点Java语言的知识,在这里纪录一下学习过程,希望能给自学Java的同学提供一点小帮助!(当然,也能方便我以后的复习用^_^) 在学习过程中有什么 ...

  6. visual studio code断点调试react

    在项目配置文件   .vscode\launch.json 中添加:   "sourceMaps": true,   "skipFiles": [   &quo ...

  7. Excel 函数使用

    字符串 20180613 转为日期  2018-06-13,单元格内输入如下公式 =DATE(LEFT(),MID(,),RIGHT()) IF 函数内的或.与 =IF(AND(A=B,C=D),&q ...

  8. 【Leetcode】【Medium】Remove Duplicates from Sorted List II

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...

  9. 【Leetcode】【Medium】Multiply Strings

    Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...

  10. Go语言(二) 继承和重载

    继承 package main import "fmt" type Skills []string type person struct { name string age int ...