Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Swift: How many types of method available for alignment UILabel and other widget in swift?

Hello i am flutter developer and new to swift.
could you please help me to figure out which method is perfect or in which situation which method should I user for alignment widgets in swift?

Like : UILabel, Image,Padding , Row,COlumn , have two tips of method see below.

//Method - 1
scoreLabel.frame = CGRect( x: 50, y: 50, width: 100, height: 50)
//method - 2 
NSLayoutConstraint.activate([scoreLabel.topAnchor.constraint(equalTo: view.layoutMarginsGuide.topAnchor),
                                     scoreLabel.trailingAnchor.constraint(equalTo: view.layoutMarginsGuide.trailingAnchor),])
 

So now is other any other method also for alignment or which would be used in live project or right way for every devices.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Those are different approaches in laying out UI elements in UIKit. The first one is manually setting frames for your views, the other one is called AutoLayout. There’re plenty of discussions comparing their differences.

Apart from UIKit, there’s also another way of building UI for Apple platforms, which becoming more popular – SwiftUI.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading