Get outlet size within awakeFromNib

前端 未结 2 444
日久生厌
日久生厌 2021-01-18 11:45

I created a custom UICollectionViewCell containing an outlet for a label (placed in the Storyboard). I\'d like to get the height of this label from within the <

2条回答
  •  旧时难觅i
    2021-01-18 12:47

    A part of the answer is in dreamzor's response to iOS AutoLayout - get frame size width.

    The trick is to place your frame-dependent code to the viewDidLayoutSubviews method

    In my particular case, I found that adding [self layoutIfNeeded]; in my custom cell awakeFromNib method, right before asking for the outlet size worked like a charm.

提交回复
热议问题