zoukankan      html  css  js  c++  java
  • UITableViewCell的高度与UILabel自适应

    UITableViewCell内部只放了一个UILabel,Cell的高度随着UILabel内容的高度变化而变化,可重写UITableView的委托方法动态调整高度,还要设置UILabel.numberOfLines = 0

     override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
            if indexPath.row == 1 {
                //If it's content cell
                var boundSize = CGSizeMake(300, 500)
                var text = NSString(string: lblContent.text!)
                let attributes = NSDictionary(object: UIFont(name: "Arial", size: 15)!, forKey: NSFontAttributeName)
                let size = text.boundingRectWithSize(boundSize, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: attributes as [NSObject : AnyObject], context: nil)
                return size.height + 10
            } else {
                return 44
            }
        }
    
  • 相关阅读:
    day 011总结
    day 010 总结
    day 10作业
    day 009总结
    day 008总结
    wireshark 解密tls消息
    js基础 数组slice
    js基础 数组splice
    js基础 Array.from
    js基础 Array.of
  • 原文地址:https://www.cnblogs.com/foxting/p/4600573.html
Copyright © 2011-2022 走看看