Jinu George
Jinu George

Reputation: 25

How to calculate size of UILabel according to the text in Swift

I need to adjust the size of the UILabel according to its size dynamically, width may be constant but height should be dynamic

Upvotes: 1

Views: 70

Answers (1)

Antony Ouseph
Antony Ouseph

Reputation: 552

    let label:UILabel = UILabel(frame: CGRect(x: 30, y: 0, width: curWidth!, height: CGFloat.greatestFiniteMagnitude))
    label.numberOfLines = 0
    label.lineBreakMode = NSLineBreakMode.byWordWrapping
    label.font = curFont!
    label.sizeToFit();

Upvotes: 3

Related Questions