When starting to learn Swift I was confused by the auto-layout system. Wether using storyboards or programmatic constraints, It simply didn't mesh well with me. Some constraints interfered with others at runtime, and it became frustrating to sort through all the different conflicting constraints. I admit that using auto-layout in Xcode is quite powerful, but I believe the additional complexity in addition to the increased computational costs of auto-layout calls for an alternate solution. Notice in my title I did not say this is a "better" way to layout views, just a different approach that could breed further experimentation



I felt there was a more concise, less computationally expensive way to lay out views, so I began working on a little side project I call View Layout. It's simply an extension of UIView, where you're instantiating a struct (ViewLayout) that calculates a view's position for you. All that math you may do laying out views with CGRects and frames? It's all encapsulated in the View Layout struct. It uses the ViewPosition enum to determine the position of the view in relation to a "guide view". Instead of trying to describe it, i'll just show the code. Here is the init for ViewLayout, with the steps broken down and explained.


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


This article is related to

Swift,Swift4,Core Data,iPad,iPhone,iPhone Resources,iPhone Articles,iPhone Development,iPhone Turorial,Mobile Development Tutorials,Mobile Developments,Objective C