//这个frame是初设的,没关系,后面还会重新设置其size。     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];     label.numberOfLines = 0;     label.backgroundColor = [UIColor clearColor];          NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20],};          NSString *str = @"abcdefg你上课可是你的拿到了";     CGSize textSize = [str boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;;          [label setFrame:CGRectMake(100, 100, textSize.width, textSize.height)];     label.textColor = [UIColor greenColor];     label.text = str;     [self.view addSubview:label];

iOS UILabel根据字符串长度自动适应宽度和高度的更多相关文章

  1. 根据NSString字符串长度自动改变UILabel的frame

    相信大家都遇到过这种需求.如果一个不慎,容易做成这个模样: 话不多说,上代码. 1.首先,设置UILabel的相关属性 UILabel *tmpLabel = [[UILabel alloc] ini ...

  2. IOS 获取中英文字符串长度

    //得到中英文混合字符串长度 方法1 - (int)convertToInt:(NSString*)strtemp { int strlength = 0; char* p = (char*)[str ...

  3. 百度的富文本编辑器UEditor批量添加图片自动加上宽度和高度的属性

    若是没有对编辑器做任何配置直接添加图片的话,显示的html内容如下图所示:它会显示出原图片尺寸 所以必须要对图片的初始显示尺寸做控制:ueditor文件中找到image.js文件 在image.js中 ...

  4. ios常用的字符串NSString自动释放理解

    最近在做程序的时候,突然发现对于NSString的理解还是存在问题的.因此补充一片blog,希望对刚刚进入OC开发并搞不清楚内存泄露问题的人一点指引. 赋值: NSString * str = @&q ...

  5. Android下如何计算要显示的字符串所占的宽度和高度

    Rect bounds = new Rect(); String text = "Hello World"; TextPaint paint; paint = findViewBy ...

  6. iOS小知识:计算字符串长度(如果有表情,表情的长度为1)

    在做项目的时候,textField能够输入表情,但是iOS的表情是占两个字符的,再计算字符串长度的时候就和想象的不一样了,所以用了次方法会将表情的长度转成1,最后得到的字符串的长度就是能看到的实际的长 ...

  7. 扩展entity framework core 实现默认字符串长度,decimal精度,entity自动注册和配置

    报道越短,事情越严重!文章越短,内容越精悍! 文章以efcore 2.0.0-preview2.测试验证通过.其他版本不保证使用,但是思路不会差太远.源代码 目标: 1.实现entity的自动发现和m ...

  8. Android开发经验之获取画在画布上的字符串长度、宽度(所占像素宽度)

    Android中获取字符串长度.宽度(所占像素宽度) 计算出当前绘制出来的字符串有多宽,可以这么来! 方法1: Paint paint = new Paint(); Rect rect = new R ...

  9. ios 计算字符串长度<转>

    - (int)textLength:(NSString *)text//计算字符串长度 {     float number = 0.0;     for (int index = 0; index ...

随机推荐

  1. Charles 3.11.5 绿色特别版

    Charles 3.11.5 绿色特别版,注册码在key文本中 链接: http://pan.baidu.com/s/1hsoFcyS 密码: q6e1

  2. JAVA_Java中关于supper和this的理解

    2015-04-04 Created By BaoXinjian

  3. Gridview导出EXCEL(多页) z

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  4. java基础要点

    Java语言是现在比较常用的编程语言,因为Java语言可以编写桌用程序,也可以编写web程序,还能编写嵌入式程序.这是由于相比脚本语言,Java 的运行速度要快.而对于底层语言,Java与平台无关,可 ...

  5. 2.6内核LOGO制作方法

    http://blog.csdn.net/tommy_wxie/article/details/8594286

  6. Linux ToolChain (二) --- Linker (1)链接选项 -L -rpath -rpath-link

    一.动态库的链接和链接选项-L,-rpath-link,-rpath (1). 现代连接器在处理动态库时将链接时路径(Link-time path)和运行时路径(Run-time path)分开, 用 ...

  7. vbs脚本总结

    1.  msgbox语法:msgbox "对话框","对话框标题" 例:const hw="Hello World!" msgbox(hw) ...

  8. 网站搭建 so easy

    服务器(国际购买):http://www.gigsgigscloud.com/ 域名(阿里云): 解析到服务器       服务器需要安装 1.putty 2.CuteFTP(自己感觉这个靠谱点) / ...

  9. C#修改文件夹权限

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

  10. SqlDataReader的使用

    1.建立数据库连接: 2.设置数据库指令: 3.数据拾取器接收输出的数据: 4.遍历打印数据: using System; using System.Collections.Generic; usin ...