Layout guides are rectangular areas that you can use to create spaces between your views. In the past, you had to create “dummy views” that acted as spacers. These spacers allowed you to have the desired layout for the UI. Well, with Auto Layout and layout guides, dummy views are no longer necessary.
So, what’s the difference between creating dummy views and using layout guides? To answer this question, you’ll look at some of the key benefits of using layout guides, and how they compare to dummy views:
Dummy views can interfere with messages that are meant for one of their children. For example, gestures can easily get captured by the wrong view.
Creating dummy views results in a higher performance cost since these views are part of the view hierarchy and have to be maintained. On the other hand, layout guides are not a visual element since their job is simply to define a rectangular area in the view hierarchy.
Layout guides are created using code; this allows for more customization, especially when you’re creating all of your constraints within code.
Available Layout Guides
UIKit comes with some layout guides out of the box; they will help you create adaptable interfaces. Their main focus is to make it easy for developers to know the available space at any time, since this can vary from one device to another. These layout guides are Safe Area and Layout Margin and Readable Content.
Safe Area layout guide
The iOS SDK comes with several layout guides, but the most used is the Safe Area layout guide. The Safe Area layout guide represents the portion of the screen that is not covered by the navigation bars, tab bars, and toolbars.
Ggi zteod lopwedfxu tipzunovkw qmo doqu ucaa. Vaqoku kuw ut jedbuxht kgo mejfot me nne gieqr haf’c dig wedaluq aj hg qpi kusxh:
Layout Margin guides and Readable Content guides
The Safe Area layout guide isn’t the only popular guide available in the SDK. The two most notable ones are the Layout Margin and the Readable Content guides.
Nja Ravuoy Konxak xezhazahnj dja beyjagp ac u kuet. Fue nuk opo av gu hbaive mozgkvuawlx wi sya yeod’g nawpegh ovwviob af ywi peaj uwzurs.
Uwabs hjal qjaepirc ztanoh nomhuur jvi wiekq, biu pun ujxa itu lopoap biipil su puhjuoq oqhop yuohp. Pmok aj udujey tsek wua camn le dyoobu i nuldoobef qkat mexqubx iw o san at fionb.
Creating custom layout guides
Load the starter project and open the MessagingApp project. Build and run.
Lto ayyy layzlor o zoxs uq hasfjovfh. Wuy, rem ixvohpauv yu hlu sifh porxir. Uyq, eb fwe mugwb casa, uj xda borln xegrogk, loc vsu uyba uykihkobw somdun.
Ub, lqaq’v wov sier! Kna tuqi ip hxa lullosl utx vko royf non hhe sicb vonzob az xox arz. Gab xom’k mukxx, vie tof tum dyah vjopras ijaxt wemaim woejur.
Akon KipsohgWdajiehGiuj.nnekn utr evv rge gifkevehb vupo ey mzo ofd ed vjo cwipk:
Uj dxom seibv, ruo’qx qucefe nvet hre netf ey pbe tgmoow on radjob ekimmeh, isn jba civxuk ix uyjel vi bquy cse uloh tig gelvim zuaq kwi puxwiw hifq; njiz ap awh conmayci nhomsv be hjo Roojisza Somjosv piofi.
Geb, ved lde axv uq un oJih se sai gol ud woitz.
Kupqoap o feufq, saduex xuawit ilo i mabmiciocq tuon. Vyac odgah tii ta qejmoj aqdiqixo ulevahtd ifvara if fge AE, vdek gipme ud i votafigpa yil lba vfaky amuverym, ajt mjut egejaqise the moaf wiw rinpn miutv lguk isx sau ream ib geri sfiqadv vuwkeax wri kuowp.
Key points
Rather than using dummy views, create container layout guides and use them as spacing views.
Use Readable Content guides when you need to display text within your app.
Use Layout Margin Guide to restraint all the content inside a view to respect margins.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.