iPhone - Adjust UILabel width according to the text

后端 未结 7 1594
天涯浪人
天涯浪人 2020-12-28 08:17

How can I adjust the label Width according to the text? If text length is small I want the label width small...If text length is small I want the label width according to th

7条回答
  •  我在风中等你
    2020-12-28 08:42

        // In swift 2.0
        let lblDescription = UILabel(frame: CGRectMake(0, 0, 200, 20))
        lblDescription.numberOfLines = 0
        lblDescription.text = "Sample text to show its whatever may be"
        lblDescription.sizeToFit()
    
        // Its automatically Adjust the height
    

提交回复
热议问题