在网上看了一些,发现很多关于自适应高度的,不能用,就在下面写一种我常用的吧!保证可以直接粘贴复制到Xcode中运行。

UILabel *label = [[UILabel alloc] init];

label.text = @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

//系统默认的是单行,0表示多行

label.numberOfLines = 0;

//200表示每行的最大长度为200,不足200的按文本长度

CGRect rectOfText = CGRectMake(100, 100, 200, 999);

rectOfText = [label textRectForBounds:rectOfText limitedToNumberOfLines:0];

label.frame = rectOfText;

[self.view addSubview:label];

UILabel自适应高度的更多相关文章

  1. UILabel 自适应高度,宽度

    mLabel1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, 10, 1)]; mLabel1.text = @"my label 1, ...

  2. iOS之UILabel自适应高度、宽度

    下列两条自适应高度和宽度的自定义方法:

  3. UILabel自适应高度,自动换行

    CGRect rect; rect = self.labelInfo.frame; //UILabel高度自适应 rect.size.height = [self.labelInfo.text bou ...

  4. 【转】UITableViewCell自适应高度 UILabel自适应高度和自动换行

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {     ...

  5. UILabel自适应高度和自动换行

    码: //初始化label UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)]; //设置自动行数与字符换行 [l ...

  6. iOS开发-使用storyboard实现UILabel的自适应高度(iOS8)

    好久没有写博客了.以后多写些博客,对自己是一种提升.对大家也是一种帮助 近期特别痴迷storyboard和xib的可视化编程,在写项目的时候遇到个问题就是怎样使UILabel自适应高度,查了好多文章博 ...

  7. iOS 设置UILabel的行间距并自适应高度

    NSString *contentStr = @"总以为,在最初的地方,有一个最原来的我,就也会有一个最原来的你"; UILabel *tempLabel = [[UILabel ...

  8. IOS UILabel 根据内容自适应高度

    iOS Label 自适应高度  适配iOS7以后的版本 更多 self.contentLabelView = [[UILabel alloc] init]; self.contentLabelVie ...

  9. IOS7.0 UILabel实现自适应高度的新方法

    //IOS7.0中利用- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attri ...

随机推荐

  1. Android中用友盟实现QQ的第三方登录

    //首先应该去友盟的官网注册你的账号,创建一个应用,获得它的APPkey,也可以用它的API上的appkey,下载SDK,下面根据API文档一步步实现就行了. //下面是友盟的APi文档 1.  产品 ...

  2. java 文件字节输出流

    Example10_5.java import java.io.*; public class Example10_5 { public static void main(String args[]) ...

  3. elasticsearch高级配置之(一)----分片分布规则设置

    cluster.routing.allocation.allow_rebalance 设置根据集群中机器的状态来重新分配分片,可以设置为always, indices_primaries_active ...

  4. js zhi网马

      大家对木马都不陌生了,它可能要算是计算机病毒史上最厉害的了,相信会使木马的人千千万万,但是 有很多人苦于怎么把木马发给对方,现在随着计算机的普及,在网络上我相信很少有人会再轻易的接收 对方的文件了 ...

  5. 一个好用简单的布局空间EasyUI

    之前项目中都是前端来新写的页面,对于很多后台管理系统来说,新写页面其实比较麻烦. 最近看到一款还是不错的开源页面框架EasyUi http://www.jeasyui.com/index.php 这是 ...

  6. Chapter 1 First Sight——14

    I parked in front of the first building, which had a small sign over the door reading front office. ...

  7. 第13章 Swing程序设计----常用面板

    面板也是一个Swing容器,它可以作为容器容纳其他组件,但它也必须被添加到其他容器中. Swing常用的面板包括JPanel面板和JScrollPanel面板. 1.JPanel面板 import j ...

  8. AJAX(XMLHttpRequest)进行跨域请求方法详解(三)

    注意:以下代码请在Firefox 3.5.Chrome 3.0.Safari 4之后的版本中进行测试.IE8的实现方法与其他浏览不同. 3,带验证信息的请求 身份验证是Web开发中经常遇到的问题,在跨 ...

  9. listview的简单封装

    package com.itheima.googleplay.ui.view; import android.content.Context; import android.graphics.Colo ...

  10. Mysql程序

    drop table if exists comp_ap; create table comp_ap as select ProjectName, ModelCode, 'AP_ACMClosed' ...