How to give dynamic height to UILabel programmatically in Swift?

前端 未结 8 1629
夕颜
夕颜 2021-01-02 00:11

I have taken UIlabel which are generated dynamically using for loop, each type diff text is assign in label, I want to give UILabel size dynamically depending on text.

8条回答
  •  -上瘾入骨i
    2021-01-02 00:46

        myLabel.text = "Your Label Text Here"
    
        myLabel.textAlignment = .Natural
    
        myLabel.numberOfLines = 0
    
        myLabel.sizeToFit()
    
        myLabel.frame = CGRectMake(myLabel.frame.origin.x, myLabel.frame.origin.y, 280, myLabel.frame.height)
    

提交回复
热议问题