Reducing Line Spacing of Text in SwiftUI

EDIT: Unfortunately this stopped working in Xcode 15 as the function is now marked internal and there is no other option available. Damn Apple!


Based on tadelv comment.

lineSpacing does not accept negative values, but you have a hidden API _lineHeightMultiple that works. It says it’s deprecated but the suggested one does not exist!

var body: some View {
  let font = UIFont.systemFont(ofSize: 12)
  let fontLineHeight = font.lineHeight
  let desiredLineHeight = 24.0

  Text("text")
    .font(Font(font))
    ._lineHeightMultiple(desiredLineHeight / fontLineHeight)
}

Remember that using private apis could be rejected by App Store Review or break on future ios versions. Use at your own risk! (Damn Apple!)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)