Resizing a UILabel to accommodate insets

后端 未结 8 1719
梦谈多话
梦谈多话 2020-11-27 11:03

I\'m building a screen to scan barcodes, and I need to put a translucent screen behind some UILabels to improve visibility against light backgrounds.

He

8条回答
  •  独厮守ぢ
    2020-11-27 11:08

    In additions to Nikolai Ruhe's answer, you need to invalidate intrinsic content size for autolayout to properly recalculate the size changes. You would notice this issue if you change edgeInsets over the application lifecycle:

    class NRLabel: UILabel {
    
        var edgeInsets = UIEdgeInsetsZero {
            didSet {
                self.invalidateIntrinsicContentSize()
            }
        }
    
        ...
    }
    

提交回复
热议问题