UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: Question about Visual Format Language

Forums > 100 Days of Swift

So I'm at project 6 of 100 days of Swift. I'm currently learning about writing auto layout/constraints programmatically. The syntax of it all just looks stupidendously trivial to write, it makes 0 intuitive sense to me.

My question, is there another way of writing out these constraints programmatically besided VFL?

view.addConstraints( NSLayoutConstraint.constraints(withVisualFormat: "V:|[label1(labelHeight@999)]-[label2(label1)]-[label3(label1)]-[label4(label1)]-[label5(label1)]-(>=10)-|", options: [], metrics: metrics, views: viewsDictionary))

Makes no sense.

3      

Yeah VFL is a crazy thing, I never used it really. And yes there is indeed a way using something called layout anchors where you basically create constraints like any other objects in code. It takes lot of lines of code but they mostly aren't complicated and can be made shorter with helper methods and extensions.

5      

@nemecek-filip thank you alot for the answer. This is all really strange to me, coming from the web world I would have assumed that Apple could have come up with a lot more elegant way than this. Also the anchor thing doesn't seem very clean too. I guess this is also why they came up with SwiftUI no?

3      

Well the UIKit is there since the very first iPhones and so it evolved gradually on the available foundations I dont think developers would be stoked to learn new UI framework every two years :-) But yeah SwiftUI is answer to this and other UIKit complexities.

4      

@nemecek-filip Thank you a ton Filip.

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.