美文网首页
Simple steps to add self-sizing

Simple steps to add self-sizing

作者: lyuan | 来源:发表于2015-07-23 14:19 被阅读0次
  1. Set the estimatedItemSize property of the flow layout to a non-zero value.

    // Inside the view controller that has controls a collectionView.
    override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
      let flowLayout:UICollectionViewFlowLayout = collectionView.collectionViewLayout as! UICollectionViewFlowLayout
      flowLayout.estimatedItemSize = CGSizeMake(100, 30)
    }
    
  2. Use constraints on the collection view cell content view,
    or override sizeThatFits:.

    // Inside the custom collection view cell class, override |sizeThatFits:|.
    override func sizeThatFits(size: CGSize) -> CGSize {
      return CGSizeMake(*customWidth*, *customHeight*)
    }

相关文章

网友评论

      本文标题:Simple steps to add self-sizing

      本文链接:https://www.haomeiwen.com/subject/nhzpqttx.html