Figure out size of UILabel based on String in Swift

后端 未结 11 1508
执笔经年
执笔经年 2020-11-22 13:35

I am trying to calculate the height of a UILabel based on different String lengths.

func calculateContentHeight() -> CGFloat{
    var maxLabelSize: CGSize         


        
11条回答
  •  -上瘾入骨i
    2020-11-22 14:14

    @IBOutlet weak var constraintTxtV: NSLayoutConstraint!
    func TextViewDynamicallyIncreaseSize() {
        let contentSize = self.txtVDetails.sizeThatFits(self.txtVDetails.bounds.size)
        let higntcons = contentSize.height
        constraintTxtV.constant = higntcons
    }
    

提交回复
热议问题