zoukankan      html  css  js  c++  java
  • ios--动态计算label的高度

    #import "ViewController.h"

    @interface ViewController ()

    {

        UILabel *dynamicLabel;

     

    }

     

    @end

     

    @implementation ViewController

     

    - (void)viewDidLoad {

       

        if (!dynamicLabel) {

            dynamicLabel=[[UILabel alloc]init];

        }

            dynamicLabel.backgroundColor=[UIColor redColor];

            dynamicLabel.font=[UIFont fontWithName:@"HelveticaNeue" size:24.0f];

            dynamicLabel.text=@"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus eu urna quis lacus imperdiet scelerisque a nec neque. Mauris eget feugiat augue, vitae porttitor mi. Curabitur vitae sollicitudin augue. Donec id sapien eros. Proin consequat tellus in vehicula sagittis. Morbi sed felis a nibh hendrerit hendrerit. Lorem ipsum dolor sit.";

            dynamicLabel.lineBreakMode=NSLineBreakByWordWrapping;

            dynamicLabel.numberOfLines = 0;

            CGRect tempRect=[dynamicLabel.text boundingRectWithSize:CGSizeMake(300,1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:dynamicLabel.font,NSFontAttributeName, nil] context:nil];

            dynamicLabel.frame=CGRectMake(10, 64, tempRect.size.width,  tempRect.size.height);

        

            [self.view addSubview:dynamicLabel];

    }

  • 相关阅读:
    epoll源码实现分析[整理]
    linux几种时间函数总结
    linux几种定时函数的使用
    linux下redis数据库的简单使用
    网络编程之非阻塞connect编写
    网络编程之select
    数码相框(LCD、I2C)
    centos tftp和samba的安装与配置
    libevent库简单使用
    c语言随机数
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4120956.html
Copyright © 2011-2022 走看看