TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

How to transfer the line parameter from figma to swiftUI layout?

Forums > SwiftUI

Good day everyone. Guys who faced layout in figma? Tell me how to interpret the parameter "line height" in the layout of the swiftUI? Something didn't google anything. 🙄 Picking this modifier .lineSpacing(120)

Just picked this answer. But not working. Answer by Ole-Kristian

let font = UIFont(name: "SomeFont", size: 16)!
return Text("Some Text")
    .font(.custom("SomeFont", size: 16))
    .lineSpacing(32 - font.lineHeight)
    .padding(.vertical, (32 - font.lineHeight) / 2)

3      

Figma website says that - "Every Text layer will now calculate Line height percentage, as a percentage of the Font Size".

So I can calculate the height of one line as...

let calcPrecent: CGFloat = (fontSize / 100) * 120    //Line height 120  (size height from Figma)
let padding: CGFloat = (calcPrecent - size) / 2
Text("Example")
  .padding(.vertical, padding)

But I didn’t find the information on how .lineSpacing() is calculated in swiftUI.

2      

Guys, who knows the solution? Tell? I've already tried everything!

2      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.