negative line spacing swift code example

Example: swift negative line spacing

var attrString = NSMutableAttributedString(string: labelText)
var style = NSMutableParagraphStyle()
let minMaxLineHeight = font.pointSize - font.ascender + font.capHeight
let offset = NSNumber(value: Float(font.capHeight - font.ascender))
let range = NSRange(location: 0, length: labelText.length)
style.minimumLineHeight = minMaxLineHeight
style.maximumLineHeight = minMaxLineHeight
if isCentered {
    style.alignment = .center
}
attrString.addAttribute(.paragraphStyle, value: style, range: range)
attrString.addAttribute(.baselineOffset, value: offset, range: range)

labelText.attributedText = attrString