Functions that calculate the size of uilabel based on different string lengths.
- iOS 12.0+
- Swift 5.5+
- Xcode 10.0+
File > Add Packages > https://github.com/donggyushin/DGLabelSize
pod 'DGLabelSize', :git => 'https://github.com/donggyushin/DGLabelSize.git'
let label: UILabel = {
let view = UILabel()
view.text = "short text"
return view
}()
// Get label's height
DGLabelSize.height(maxWidth: maxWidth, maxHeight: maxHeight, label)
// Get label's width
DGLabelSize.width(maxHeight: maxHeight, maxWidth: maxWidth, label)