首页 > 编程语言 > 详细

swift UILabel的高度自适应

时间:2016-05-25 10:52:41      阅读:189      评论:0      收藏:0      [点我收藏+]
        let label = UILabel.init()
        label.backgroundColor = UIColor.grayColor()
        label.text = "1234567890-edfdgddffgfgfggfggddfbyfru6y6r7iuymgnjnrtfugyu57t6injyunjokn89uilmghbjl,hknjlllllllllllllllllllllllllllllllllllllmimomomkjnijunbuygbtyfrtdrxcresxweaswa"

        label.font = UIFont.systemFontOfSize(14
        )
        label.textColor = UIColor.redColor()
        let string:NSString = label.text!
        let options:NSStringDrawingOptions = .UsesLineFragmentOrigin
        let boundingRect = string.boundingRectWithSize(CGSizeMake(200, 0), options: options, attributes:[NSFontAttributeName:label.font], context: nil)
        label.frame = CGRectMake(0, 20, 200, boundingRect.height)
        label.numberOfLines = 0;
        label.lineBreakMode = NSLineBreakMode.ByWordWrapping

        self.view.addSubview(label)

 

swift UILabel的高度自适应

原文:http://www.cnblogs.com/yaoyao0110/p/5525838.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!