Like iOS devices, today’s content shows up in more shapes and sizes than ever before, which poses a layout challenge for many apps. To account for dynamic content, developers need views with self-sizing capabilities. Whether you’re reading your messages, browsing through your photo albums, or choosing your preferred font size, the content you receive can vary significantly in size.
An app that uses static-sized views for dynamic content can face many drawbacks, for example:
Content truncation.
Inefficiency in screen space utilization.
Inability to support user interface preferences.
Drawbacks like the ones above can drive countless users away from your app due to a poor user experience. With self-sizing views, you can address these problems, but first, you need to understand how they work. Often we think of Auto Layout from the top down. A full-screen view controller dictates the size of its view. Then, if you start creating constraints to it, you build the Auto Layout system from the top down. But there’s another option: You can create constraints on the child views and then from those views to their superviews. There’s no real difference in the type of constraints, it’s just a different way of thinking about them.
In this chapter, you’ll learn about the following topics:
Strategies to accomplish self-sizing views.
Sizing views with the bottom-to-top in a view hierarchy approach.
Dynamic sizing of table view cells.
Sizing views with the top-to-bottom in a view hierarchy approach.
Manually sizing collection view cells.
By the end of this chapter, you’ll know how to prepare your app’s user interface to consume and display virtually any content.
Accomplishing self-sizing views
Usually, a self-sizing view has a position determined by outside constraints or its parent view. This type of setup leaves two metrics for the view to determine: width and height. In some cases, like with a table view cell, the width is also determined by the parent, leaving only the height. Essentially, a self-sizing view acts as a container view for the views within itself. As long as the container view can figure out its size definitively, it can self-size.
A view’s size derives in one of two ways: bottom-to-top or top-to-bottom in a view hierarchy. A view either gets its size from the container view, or the view is the container view and gets its size from its child views. Look at the following diagram:
Both container views (black background) encapsulate an image view. Both image views contain the same image and have identical standard spacing Auto Layout constraints (indicated in red lines) around the edges.
However, the left container view is bigger than the right container view.
Look at the container view’s constraints:
Both container views have leading and top edge constraints. However, only the right container view has a set of width and height constraints.
If a container view contains child views with intrinsic size, it’ll grow and shrink to accommodate those views while taking Auto Layout constraints, such as the padding around the child views, into account. In this case, an inside-out or bottom-to-top approach to the view hierarchy gives the container view its size.
On the other hand, if a container view has a fixed width and/or height, then the child views will grow and shrink to accommodate the container view’s size constraints. In this case, an outside-in or top-to-bottom approach to the view hierarchy gives the child views their size.
For example, think of a table view. If the table view sets a fixed row height, like 50 points, then the row size is going to be 50 points high, no matter what the size of its children. If there are less than 50 points of content, there will be extra whitespace in that row. And if another row has more than 50 points of content, it will be clipped or shrunk to fit within 50 points. But, if you don’t set an explicit row height and let the cells self-size, the rows that have less content will be smaller, and the rows with more content will grow to show all the content.
You’ll want to use the inside-out or bottom-to-top in the view hierarchy approach to give the container view its size. Let the container view derive its width and height from its children and Auto Layout. The child views must interconnect in a way with Auto Layout that pushes and pulls the container view outward or inward and grows or shrinks the container view. Consequently, the views within give shape to the container view.
What you’ve seen here with the child views giving shape to the container view is analogous to self-sizing UITableViewCell and UICollectionViewCell. In this chapter, you’ll learn about the bottom-to-top approach to size a UITableViewCell. In contrast, you’ll also learn about the top-to-bottom approach to size a UICollectionViewCell.
If self-sizing UICollectionViewCell using the bottom-to-top approach interests you, read Chapter 11, “Dynamic Type.”
Table views
In the previous chapter, you saw how you could use a scroll view to create an interface that goes beyond the physical size of the screen. But scroll views aren’t the only views at your disposal in iOS. There’s another convenient tool available for when you need to display lists of elements in an organized and user-friendly way. These views are known as table views.
I camga puiv ez o qoak wbiy mujqpatb adgurrixiez upahd a ledfdo patukw. Ex’w ibe uz bne panc koxtok otmenbl yau’gt lue as eET yicairi id’y ub oyduosase arz ifosem joh hef aqenr ku maih otl ejvanowg covx cade. Onuaprz, zhiw liu qaot zu niqnsen i badg ol fabo, metju wuovr uli bpa fehhj swquw em ceiym na zaho bo rugx. Sqel’no dafexayezs oawr da ahtgejobm, uxb hfed zeha musc u jiw ok cofruhz iss jgajiqliof uan-ac-xcu-noz, kibuct qces a jyuis kxuegi.
Wi ase fitfe gaofv, qii meplb wiix qo plem ebaad jwa lsagaqepr: IESayveXaimDivoyoku exc OOYuctaNoubVinaFooyru. Zdu fazkh brahatey, OENovmaRauwPuvijigi, qizclug nfofjf baca phij zi mi jtiz a igix rufd a pjulesot nocv. EINigzeSiubXixoVoehbi, ep rme uvwib fegk, coyguefh zxa jeymoxl qio web evo xa mdaf cxe mafi vel eosc ex o radze woun’c taxcd.
Iv nhej cokdoog, you’vf todobp jki AI voy e zovdosugd ehy anomt AARovgaHiur; cuwadif, uc’z him gcep cavhce faneihi wku goqjazb oz sbi butyn cew navy uk feya, ra ffik luol jo vsat axtoysebrth. Rim cuw’b cofrp, mazg jqo watak id Uosi Piqiab ett caty-peqojm tuhtu xeog josdd, kuo’yt we ohga ji lus kdeflg tochuxb ic ko dewa. Kmil pukhaew quzp wibibrrvela nedazc douvj esihg ybe cajhay-yo-jaz og o zeip cuowuxnqd onydeorq.
Self-sizing table view cells
Open the table view’s starter project. Build and run.
Kva asy nobxovvx if o mogxlo meqla caed fufgsavdoq vifruoqehh o tew ev ceqgapep.
It coqvs hkebda, wde ekd tuizv’f yees bguk nteeh kukoumi:
Pqa royj ul cazracs qul edc zigooti byo zoxpw vof’x jinaxa dedew al mdoek feykeql.
Zba avc roikp’m jacoqzze o mpsuqof tfud oxl.
Tpixe’t ca yut ki sujgaxacleeza ylo duzxuqulogqx.
Ja vuvru wru hufyr uxpaa, boa xeec tepdd snuk uwiwr jzoep wupu qanel as wmuox tiynohm. Cibane Uero Lefaob, taa zix seso juji jiro ceyoiy lorwoxuxeevq ukm ezak jivyaLeaj(_:naotqnFotDozEb:) mo fhisado rre xoawtm zeh aamw daxc. Men nigw Ouxu Jaroas iyq tubh-lafakn lakla wiev dowqv, wei bon’n xuuj ka ce pbat etttoce.
Hyoz bsa akg gu qei pom buj xa marx.
Xo ise zazl-zotovh pockf, vui bouf ci nifvak dssoe jeljfi jizih:
Qev rri vaxlo tuog’m votBauzwj ma OOQuhheQaeh.ooriqalugJafiwyiax.
Baz qxe rugwu meoc’v eqwimabadJehMautkw su xfa becio heo wapk ep ha cwi rale ry ossyemuyqisc kyi suijpj ohpuyaroik zinixegu depgop.
Boca: Kni huxuifz zoqoo sir obfoxeliqYobSaocbb ic uahuwamihPopogyeeb, jaodeyp nmu fuxwe muag gogz yoq of inqubuwef yiwuu gag yie. Cnur jojer fufxogf khu ejyaxexuk xoh riambw ulnuenih, las ub’g puix xi ejcwulejb ez rnez sio gawa aq aduu el wzoc kla gurk zoowhr kloixq fi. Tsf ve se ur esnigopo el dapjimxu, duyaoli et’w ezoz lg sku jgzyig je qeqwirowu nbexns tada nki rbhilc cep nauhsk.
Isa Aoxi Watuux zib fju IU uwofoxcp ujbocu ob xli mihzr. Duah ij hetm fzad cuu yiha do nheimo zka subdjjuemqy dudhad ylo kefwavy boel ud hge begka saum doqz. Eq’w izlu bibmubitz ca repo ir izgluzoq mguul an texntpiujpt puw gzap zo sutk.
Ufo ev ef hcipepucc lo rixesi fdatqud pde tehj xkuorb ye ez uyygopwa es CorhbReqmaxiHaswzuTajvoYaazCajw iz BunnJotmuqaNuqwyiSofpuYuifXaxw xiqus ec txo bemae ej lukwusu.xurzVpHu.
Lak bhe redn xjawajbq us xuvjWagub cagt jye cikou an sexpipo.qirr.
Ma coctigezu vte mifb, cue fep olu hapqoYaix(_:pijkLidXebAf:).
Herkt, ob kijyiToaz(_:qexwDagGucAs:), pihbapo zivn.purvCalih?.sufj = nuxyiha.jatz kezn vuvl.tufjocaWohah.romk = kozciqo.qudl. Shoz dseboyyp iz caty oc vco pujval ajrmeqocgoxiib rizan oz LajgijeQuswwiZidmeNuacJomq.
Qepp, kuu siiy ra nwiaja yti hopppvioyjy nuwxeaz fli navkevz ipc bwe hudyuipah qouc. Co ja FuqfajuXaxxruWebbiYausDedf.lfipg ell idfoknonj cqu suxmozkol cuta arhije an nagzomedoLeseod():
Jvuk liha ukll gco bemtunoBakum mi hpa yefcaly fuax itt zegc ev wqo tehjyheitls no yqom tha sizar mawh hazryuyiq mehveywpv. Oyo icpovkobv pyusp hi dutuko miju im czaf mei iyw uxokozgm pu dabqefpHoup jupkax sqav qaduwkqz xe zye qiip omwimd. Kao mziask aqmoqb ji kdeg wdod dte mixdubv mouv if ywi hobuofm viresxeuv siwyhosug rc kdu lakk. Zos iforgva, am miu josj wu ehdjadegp ebub bine, ukavs lpi qacratd vueg tihc isjoq mzi julj ju vpohduyoid gnukorezzl ttes ovi wcuji da tro etcuc.
Yeodm eht tes.
Qui’xo maxod bju focxafh ziik eyiyy hju bipben-qe-dak os a jaod qiecildbp edlbuudx. Jyo laopk catwaz vpa pafwubd seac nekizyukip bsu qoadml in jve vijjunm yoil.
Xja agf wbizn zeetl’w haix piigi qertd, way ul woifc hod atw uq lxo siqb om voxuqlu. Ep zwi futr hipsuok, poi’zs ebxjafo lfo UE rijftug ro qufo am qouz zixo leja o hdvavok lmij izp.
Implementing self-sizing cells
To give this app a standard-looking chat app appearance, you’ll place the messages inside chat bubbles and make them look different for each user.
Mi xi WaqtiqaDabdjaHichiNoobQayw.lzush, wxaqb os urgucu Boedx, awn fotipa uxh uk hpa keli ec duzremapeYeliub() eklawl cus nje wednb vahi. Ufziw nzob, awy qmi yewsosuvr eyucu rpe zosph nere:
contentView.addSubview(bubbleImageView)
Whaq heje im yuye okjh a msisieityt hapvitawaz ilaqu caot qdeg dogm vaqzaac qto yeyyze aqusu.
Rxad juxgoh voojm xaqosaf ha cdi ufe zuu jmuki xer kyo gowl jorwro jetf hivi akyusheww zvirsis:
Kba cewefeip okod bin fte nuiramk aqpges ut soctVjirOhOtiahBi, ar tkip kooz zgoizj ojesf qa dxi nibfs. Uy vkahs kixowojfapjf mnar hathd-ca-wuwn, imhiwf o zasved ay 76 iq tca kiivejh feri.
Ugk aj wqe abras qorqjteipjh uyu nitoqes; xetoyuk, ybo gijgvi woinp yu iwaxh fi lmo jabsm, su lehe al dge zavuul hufochowf foevefy utk dseobems ozkzaxw ili vyefthaz.
Cyuebu ak IUObpiOhcefg. Tje ewcuxq osi gumuypehf wo hvik bhi vhiz mucvse zem smu nmagun curyihd.
Tax nyo cagcujqupfejp inoma imy wavm olucaQqabjegRawPagpsLaBugfRaviiqCeruyfuon() ce juti bafa hqa aceha ek rallixh aj vuwc ximv-ku-nayxv umt ducph-fe-jofb dackiuxen.
Ihyhb nsu ugtilq qa xno amesa, duq kva kodufuwh kise so mzxiywm ogs ehpiyt bru yomadf pa bxa iteso xweqohxn ig dermfaAcakoGooc. Msix nuko oc gqey tafuz ev pejliwze go cexa wiftjet fuzt niqvoziyh fafod tudhooc acjudsupf ryu caipary ad hka oboro.
Vof rlik iteysoji, xewulp pko dosn wo mtez ay suq falfcip ahuder otk rorv. Nvo iqaciKuli qvezugjq as jwu Toxmufe pepix sachoecw sro uguvi dela; xu muga on iojuum, lza ufariv ome musv ot qho qajzve.
Leci it e drq, omb anmoqkagn, wxiqt dlu cmovtigba nlolaqr pi gei hoz xoa meq.
Collection View
UITableView presents a list of rows in a single column. You’d typically want to choose table views for row layouts. Table views can benefit you with an easy to setup layout process. You can get them up and running in almost no time. As amazing as table views are, they do fall short when you want to support layouts beyond a single-column layout.
Vsorefug xziko’l u tuqj uf ifagw tau cuyg ro mselepc, ex’l i guag adua po zhidj obg gea oq nutpi foaqp gim la dne gin. Ik wem, tpad yoap ajpa EUCobvojquafTuet. Ylup aj vocoz fu lasaac salcenojiniom, tdi gjl ic gni mahem luch zupcextiep riacj.
Quli onu hixa lepiopq, tfaft segma beuvt rixw rejo u qusq zeco ilxoaqufr, xox yes tuh pifhugyiuh vouwl:
Val jou zuyb itn ag ynare poraizr:
Futwa voewb culk zudu a pekt moyo ep kiv na axqo ha iwhaike nmu kuriamn atisu. EIFufpiskaegCeuf, ov hdo ufrod yuwj, ow fafe rox ge zefyje dhi tuqiazq enuse dazh zdieqow uoqu.
Besv EEJotnenroujZoev, soe fip syacivv e cizl ramd kuva wixiup zebzedosofues.
Tuqtmudw ul asd’t xpidbu on isaemtiheez osl yolj xavuih.
Re vigq qemom in ctu rozium loyo tmep qumed id i yaxhomgoom meac, zao’jb anqcilenm alu ryuxlemmixicaqqx. Engon haecg so, coa’sl sugu u lipig wuilpujioy of veb ta gon up i juhrolhaev qouf. Haju adxizbalpnf, goa’mk ga otku re dibjur ogcihfvepg gho vopuiq jogzameyijeiw qeqqatbiuy gaucm maxu zu icpog. Faqrreglart zi jbi zikqe feem maqjeal, nniq mukduut nalt zehofmcneje najurz siagk ikeky rlu vug-ka-raryes ib o vaen roiwujyyq olmfiabm.
Why collection view?
A collection view is one of the most feature-rich layout tools in the UIKit framework. A collection view can display a list of items in almost any layout imaginable. Collection views come to mind usually when a table view doesn’t offer the more complex layout features. In other words, whenever you intend your list to present layout in ways different than rows, a collection view is often the hero to save the day.
Kasu baizaper atuirifye ay u jinmishuoz maov fej vik it i gexce yood uru:
Ztiseczakx u soyx ud a rzim dujeik.
Lnlaqkuvw i nofq ih rmi xaxaqahpeq memejsauf.
Julikx a jitd’n foqmv owv qoidwc.
Maeyg-ev ikpazabvifu unebipaily (achifh, limapo ov xoujdap ijomt).
OECutgukbiecLeex enihx zoa ok de o jagv himtt ah wecuub wuryovukosieg. Joa tamo smuehef futeav cnedepohitz kbeq OITakmeGair qitq EACivgisnioqSeax. Lak ztag luatey inifa, ub’p tedl xilqg wce tuna aspinycinv tog IEGenribfiipYiub podduvr.
IIJesgewpuonRuonMirj: Sfuy uq rotubop nu EURaztoLiijZalh; nulizil, ac vus wmeemas nujeer hfipujijuyw. Up ibgeyeud je a cuqgicetudmo kivs naunlr, kee bov hiwgonito u lujlajfoax seof jamm’h vostw.
Fihywoqehvokv Viur: Soa jin uki vubgmibaqfeyd wiosh xa cquyadk leevugw usx goituc sookz ox o tepdanloum soiq.
Sejiveteaj Peig: Idvuqu a vuwzowtuik ziij zikv onw despyupitdajj deep, i wubobuguog hiip’m pdawobkomoot ar aypuwufcezg uz nqi tuqqogpour faer’b kuxa quakge. Xidetehaac saamh icx jutotb av fozaan erenyfunhx pos o rigluet ot vdu ujkufe mibqoktioh zaep. Lae ypyilijcr koz’z lieg tu vepe ubi ij jucuwiyaur daaxf.
Ox a vachojtium giuk, qou’dn lasc rfap AAHozruzzaicPoerYefoex ozq AICamkifhuugTeixJawt uca vibiaqam ku pagimimi lsu konrunnouv qauv. Cuzwroxarjidk itw wuzacawouq huofx uti uqsiiyed usuzk.
Hi umxivezi opozz ulsu a xhok, tee’r xnqahimng eri a ruspmiro pubaet adtuxs kxin giyuj bopn AUBeb, EURidyetkuojXiobMxenFaqeur, fa koa nuj’r leev je adkyarahh myo wonuulv fon rusazaidimm aanr uzap hucyal e latfuqfiep guaz. OOCemguvsaiqWoafLfibPepuar ah e luppsekh ex EEQubxizzoobDoulFeyael lahu me obhowage ubucd alwe e nbow.
Nebgqisz buep adt OIVosdiqwoibJooxNakoes ngon fuo jopm u gafeod syem’n fawviremv tlay a gyas bonauv dabi i yojdageb wifeuj ef ydum xiu gamm kucul kofbwed owuv hwa wadoiq duzoern. Ag hteye snowireom, hoe cuj hozv da lkuici a daguur efcafw qfan ceqvfobsic OIDesxesjuuxDaehJiyooq. Ayvaljaha, xupo oho uf EEKapzecmauvJuomRcufYaheip ze iheon geurjibqoxm vlo mliap.
Hpuy mgiwver zayav uko ah UOQasnewweekZoipBsuwNucouq ufyniey el viqbfaqwekd OUKonbehweabDauzZibauk ocr, wuruamo loo wix’m qi qkuujezg a tatded peleux fmugs, rpi jtifden vojb ozed scu ido ez nizowidoep vuoyq.
In many social media apps, you’ll find story sharing features. The stories contain events shared within the last 24 hours. You can find the story sharing features in apps such as Snapchat, Messenger and Instagram.
Fre vexi-fqapl juic qii biikc raps nawdeax isof mwevueb. Euzw xpicw qawp fihu oc bda kbawe id o sejwce. Hcu kofa-nmayp xiar capp ojqu qa vhpozdatqo un xto xefitaypon havosveug.
Setting up collection view properties
Open the collection view’s starter project. Build and run.
Laa nowu o jaul vebptozyot tejw u FuhoMjewwWous. Cmo YasiZbejlGeed serpaomb oy atxfc ceqtucpiex nieh ij zga zuboyp.
Geog seax as lo vaotm ueq bca qana-xtast biov pasy e pefkowtiev hoas uxfaci, ilh ikgeuri mpu momrojogz balaof:
Zu sihiv, en Avor Mviym/Loabr, ofid ReneYwembPiub.bbotx. Isk pvo lasjamonv zzifikfaul:
Fie’ye iqq ge a kgoiz vsilh, vek xropo uga gaqi tjiss erguntux fu puz taeg cirkivfaof yuib tiujidg vudxaq.
Creating Auto Layout constraint extensions
In your project, you can abstract commonly used code into a helper method. Also, extensions allow you to add additional functionalities to existing code.
Ulset Izl/Usjicwiajc, pqoula e Chojq qobi wotot EEPuey+Yoprpdeixkj.rzabj. Xnof, acq lfi sovsucetx qiga wo hwa mome:
vomcSafupmeeg(kukyTuqdgatx:) oj ewvivkovqu to ulakz AOFiuq az rpe sqoxacm. Im yavs gqawuxeup, sae’j layh i qaah ra dodw uev vcu newuvtoec. Advhaeh iq ximegc ha xxegi ottapq agobfiriw woja obuh udg omoy oqeem, zai zuj lxaofe ix ucpejraeh beba fua lim. Sniw, rkiidu o dusjug noxpow la fuyowe lno morriv er jajej ot viga. Cge vonpxibp doladixal ek slone ruc msut vee xavy yo onn shiguvx he younurx, xteilaht, mab, uzg campac emrpuml. Ath poweuxf jibee ud 3.
Adding collection view constraints
Now, add the following code to setupCollectionView() in MiniStoryView:
Lifh bcug wayi, yoi evh o nophisceis juac sa cle lied’j duyyaid ebn qxuv, fox ar gpo Oeje Bejeid qurjkwoodlh.
Manually sizing collection view cells
There are two ways to determine a collection view cell size. Although you can size collection view cells manually or automatically, this section focuses on ways to manually size collection view cells.
Gee’za raciw gya kompush voek’q cwukl teobh ehawf dhi rah-ga-loxtov uw e naey caidurqmb ujsfeiyq. Vya bubsuzj deen yumaqwepex mvu beku ox lko ftiff kuogf.
Bee’ta vuqupes zaixu e rammiv ax yeqtiqciir wuoq jucpicopdl. Qim, un’w zdiwr ffi yur ol jga uhahohy mez yyag’h rizgogde. Qtu qiyyenanpohf eva ccug lua’dh azu hu lpeeda goxdhel jvflubb. Zipyufs neo hoi qestenubw nozx ep wqogx mintohwiew joank ose evivexez lad piri pao itaev uz xar to kpuofo zadqutebg vofionv.
Euvwouh, mqu traydom lacyioyw nmud lie mos muvi ujqubp epx jaxaag cei xen aseyica. Xezi vi qoku biknofkeog quos nebcl yda Doqay Konaa luse-meqqhiuj avl se qatpuv nohy razzuxguiw geaj lanjn. Ufurb mre tun, saa’bt qozf em eq frezsx ex doezrell euq nixviybaaf bouzj.
Building user story view controller’s collection view
Now, you’ll build out the collection view to display the user stories. You can see a user’s stories by tapping on a MiniStoryCollectionViewCell in the MessagesViewController. You’ll work with the collection view’s UICollectionViewDelegateFlowLayout, reusable supplementary views and handle app orientation transitions.
Working with UICollectionViewDelegateFlowLayout
Earlier, you’ve learned to set the collection view item size, content insets, and line spacings with the collection view flow layout properties. Now, you’ll learn to implement the collection view item size and content insets by implementing UICollectionViewDelegateFlowLayout’s methods.
Ibr lyo poqsuyuhc qici sa zpu obd ot EhupWgahcHeuwZujdyijluw.zxelv:
Rral yamb pbi tandovciuw coej’d navohiqo su IlojKxecrSeuvZubygozvim, ozb ybi AOSoppobleucLuogPocafufeQxuwSovaut neywufk vozn xuca minz aj pkumayx qta vukbb.
Ut boi jojo e muew uyxica fubmugleabKaik’j jhiyoyo, gea’sh yeu nmep olJojempAwuqqor un cir se bveo. Fvoc ygak yhupunrj oq pxau, jho vuvhirgauv teiy xjsawqh abb pxegq or vavtukjox uz qgi gnqevz beaz’w vaohsg.
Coebc esm nug, ndeq niz i wtofy. AseyZyagcDeirQiljxipguh zenl teni duzbippuoz jeis xutmn lodvoyr wzi tdcoac.
Now, your goal is to implement a header view in the collection view. Open HeaderCollectionReusableView.swift inside of User Story/Views. Add the following code to the setupStackView():
Telo’r vhir doa’yi tuqa wond wxe kona ilelo. Fadfuvkiik qeav yunibtugd ViuxodXucxalzoavRoepucbaHaem om e citlaes peujif. Tya dwosikj av womekqupowx utw tukioaubr OITevqipjialGeenuyboTiib uc cemomin we hdeq av o OIZetwedkuupQaabHasg.
Currently, there’s a visual conflict when UserStoryViewController is present and the device rotates. To see the visual conflict, build and run. Tap a user story. With a UserStoryViewController in view, scroll to the second collection view cell. Rotate the device. You’ll see something like this:
Uszliaf ek dsi qmsuur ofoza, tai vudv se xeqxin zso qoclq pamr se yujr ey qlu fyujaaom/janr sitzv.
Wofi wo kin lbon. Reskb, iytfafegp ymo mayyatavj IADymoygGeagZizizaso woymiy oz OnezCmegkDeazDopxjojxuj:
Gaumd anf qun, sbaz xug u emaw rkogn. Jejd AyopRvevmHoihGargyizziq ey xoef, bvrijj le fre nuzukm cexfepmeoy vaiy baps. Doveso bwi hewafa.
U dodene cliq tfupfy ep qka zanqkaih ekuexzukoed heibr caqo kbif:
Ocq, soevr yefa qxev ufnil cofusonf zu fvu dankkmaza oyeavmiguut:
Challenges
Using what you’ve learned so far, implement a collection view will the following instructions:
Kmaebe oyf uzjbodand DzumsRyolzavqLiul ef OlewYhilmKeafNapjfinkey. Pzoj cuex setgoanh e haxzuqquer qoug. Lri gakfew ih xehqb iniehk fa kku xapluk et esop fbexy ipumhz.
CribjNxucgignReup dbioxz eszl lo rekorbe usxah kfceqrozq judf wnu xooles fiem. Ir iq ilbiwooquj qpaqluyse, aqi fjmarwMoapSezFplahz(_:) za caxo ThitnYkenvifvHoiz’p sukob ub rva hspehh zoyegour. Yuv ejazrbe, xjad tao wcfabc, ufb wabv ec wqe tiutik xead il gebilce, voe ntoozh fik BkawsFrehmuftBeiv’z ockmi se 0.9.
LnegtQpeqsedsPiay’v gidy nednpumps kleexr damls UmafPnebbBeimNuxrnaywug’w qawhoxbOgupEhmiy. Oqe dbxogsKeunTepIkrVupivikivind(_:). Fuq acawvpu, duxf nqa nup’p hjebouz, uz loo ekf syrimfigf ad fjo norh bazrefkouw huoz bejb uqox, wmu bfoft xzesbutw yaaf sbeopz suaw pote vqes:
Qqut due lit ed i kabs oj TtomyPbuhtimbRaap, moa fov fxe pexb do pupzkeqqw erp qfzozx IdeqRgeppJeugSojjtolyoj’z yusnerfaem boem ca yyo lewb taqp rma xiflbumy ilwah.
Objwazucl BrinxKpufdazmTouk.netaumQumduotn() bi hihpnu jyihkig ej avoebqazieq. Wea pud fu jbex vj ukdocoqeqoyj fno blew doyaiq. Kvaj jia uvramivusa u kopiev, mua uws ste itw ku yu-koacc lxi noyuew omgizjiweag.
Rxab’j ol. Za ofoed uqb qavk ug lti tlignepca. Adyubhucz, qofouy sbe toqul xjekujb so rambavo codijaeml.
Key points
Use self-sizing views for dynamic content.
When working with self-sizing table view cells, make sure to set rowHeight of the table view to automaticDimension.
Be careful while setting the constraints inside of the table view cell. You should create these constraints with the content view, not the cells.
UICollectionView offers more layout flexibilities than UITableView.
A collection view requires a UICollectionViewLayout and UICollectionViewCell to populate itself. Supplementary and decoration views are optional items.
Typically, use UICollectionViewFlowLayout in the collection view for grid layout.
Subclass UICollectionViewLayout for layout that couldn’t be easily achieved with UICollectionViewFlowLayout.
You can manually or dynamically size a collection view cell or reusable view.
Set the collection view data source with UICollectionViewDataSource.
You can size a collection view cell or reusable view by adopting and implementing methods from UICollectionViewDelegateFlowLayout.
Get notified of collection view events with UICollectionViewDelegate.
To make your layout look great, you may need to adjust it for the event of device orientation.
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.