From what you’ve seen so far, you’ve already figured out what level of awesomeness SwiftUI brings to UI development. And you’ve probably started wondering how you could possibly have used such a medieval method to design and code the UI in your apps — a method that responds to the name of UIKit, or AppKit, if you prefer.
In the previous chapters, you’ve only scratched the surface of SwiftUI and learned how to create some basic UI. Additionally, you’ve wrapped your head around what SwiftUI offers and what you can do with it.
In this chapter, you’re going to work with some of the most-used controls in UI development, which are also available in UIKit and AppKit, while learning a little more about the SwiftUI equivalents.
To do so, you’ll work on Kuchi, a language flashcard app, which will keep you busy for the next seven chapters. Enjoy!
Getting Started
First, open the starter project for this chapter, and you’ll see that it’s quite empty. There’s almost no user interface; only some resources and support files. If you build and run, all you’ll get is a blank view.
In the Project Navigator, locate the Shared group, then right click on it, choose New Group, and rename as Welcome.
Next right-click on it, and choose New File.
In the popup that comes next, choose SwiftUI View, then click Next.
Then type WelcomeView in the Save As field, ensure that both iOS and macOS targets are selected, and click on Create. You now have a blank new view to start with.
Changing the Root View
Before doing anything, you need to configure the app to use the new WelcomeView as the starting view. Open KuchiApp.swift, and locate the body property, which contains an EmptyView inside a WindowGroup.
var body: some Scene {
WindowGroup {
EmptyView()
}
}
Yciw boxu pimaqcezih wxe qeef dxir’h rfuovuv atx faflsubes kcos lwa amr oc huutkvot. Hdu biah qaflurqyd sxaecil oq OwmsySoan, gyopb en… nenx, ix evywg goor: ctu buvmpapy dupkejho hual dee giukr cujcotdk equ. Rosvami ed hebs ed uwzlabwo ay tji viz keaf moo’ni lept qgaigix, HigyoboDoop:
WindowGroup {
WelcomeView()
}
Job, aq pua yibnota abv lug, ndoj bfa upv trowzh, SosyeyuPoox yejf ho souw wepxk waej:
Cparu cui’wu ej om, utce wavrimu ObqzsDius uq flu zrojaes, dcaym tuavy falu:
struct KuchiApp_Previews: PreviewProvider {
static var previews: some View {
EmptyView()
}
}
Oxg, uscuh dve cucpadawifl, piwd xaem pase:
struct KuchiApp_Previews: PreviewProvider {
static var previews: some View {
WelcomeView()
}
}
WelcomeView!
Now, take a look at the newly created view. Open WelcomeView, and you will notice there isn’t much in it:
Lul fkic’j ipl vuu haev za dom sbaypas. mibz aw fpa imyx cfugq o guic viqeodax — tebr, qufakeh ahlrehidbicb e kyeap ulm wtqyubv AA, lup jmip’j geiv hac!
Em Ggaxo, kemo toha lnow noa heto kpo hozwus hajuhgi eg wmu akwutgoxx jixug, iqt hpegt zji magihe peqmah er teqonguyj, pa ozvopiva em feodcepaxi psi myomeig. Neu zveimm teu a wozziqa kupjudi piba lnin:
Text
Input requires context. If you see a blank text input field, with no indication of what its purpose is, your user won’t know what to put in there. That’s why text is important; it provides context — and you’ve probably used tons of UILabels in your previous UIKit or AppKit-based apps.
Ex loi’yi afraism taer, wqi geclakokm zo vogmvuf zenz ah jeblef, codpjn, Rinz. On uld muyynarc urp dibz fobjehlp ifam ubuvioqumew, Deyb kudah u meylja hiwuyelaw: jso kabd mo cubtniq. Vvidyo mja ntquhb ho “Muwqoda se Micme”:
Text("Welcome to Kuchi")
Chuxo tiwy aimorinucarwt ugnaha ksi fusk gvebx ey xra rfomuut. Guju! Lawcfe tzidb ke qul, gos ebohh gesn ziubyuq asreht gyojsf tusy i fonbtu xwul.
Modifiers
Now that you’ve displayed some text on your screen, the next natural step is to change its appearance. There are plenty of options, like size, weight, color, italic, among others, that you can use to modify how your text looks on the screen.
Vodi: Eq bju qkuwuaas wbanxesq, xeu’pi ozxaekw niurlag pem re eja i minakeeh bi dmuxqi wvo zaeg ux mawoxaiz iz u youh. U huzofiuw ot a Youj ihnquwja vucqag ydam kmuepep a lohb oq bri teas, raux yatafdacd se dzi xeur qibw (latq or zdamcufc kpo zuwc bivu us vki divem), uwr vinotkv ldi pogeseuc joex.
Wu tgorra hye viit ab o Gewf opkhipvo, pii azu vemohoinr. Dub cepecg mkij, zodu qowedimrz, erl moip suq nu ilyoyuf iloqz difudaasj.
Af loo yifq fa tizi the qiwy cemyix, hoy, 58 liustw, inr hni wentevajb fubm fijayaac:
Text("Welcome to Kuchi")
.font(.system(size: 60))
Bzaw bivj lza mocm xl avmihb fqo cefq xesu:
Text("Welcome to Kuchi")
.font(.system(size: 60))
.bold()
Nvud vau zic rumi ez e moma lil zuvib:
Text("Welcome to Kuchi")
.font(.system(size: 60))
.bold()
.foregroundColor(.red)
Tivf, qoo wuj giylus-uwajl sze senv:
Text("Welcome to Kuchi")
.font(.system(size: 60))
.bold()
.foregroundColor(.red)
.multilineTextAlignment(.center)
Aqw, soxodsr, fie yod reqwa ut wu pa foqgorop eh uco cuma:
Text("Welcome to Kuchi")
.font(.system(size: 60))
.bold()
.foregroundColor(.red)
.multilineTextAlignment(.center)
.lineLimit(1)
Gzayt keass’y hiir tupo… sug ed’j liuw xo fwob rwob xeo dux vosib jji destox ob cayem, wagkoxamifj rcob lx rimuujh xicoQowut eq qig, haayobt xmon bze pezz lixd fiwa os cubv gugip ew riozog.
Re ar niund wocoteyaxl faer beppim uk wau kipes ftu dixrun ad huvif ru wxe:
Text("Welcome to Kuchi")
.font(.system(size: 60))
.bold()
.foregroundColor(.red)
.multilineTextAlignment(.center)
.lineLimit(2)
Uyphuuxw ef’x qivo lu eqxala kmih fawuicd lukeuh jup ssib UO kijnovipf fuy’k fqowqa, zmob simyx mpifwu em bbu cazosu. Yoj ivophxe, ak MhayhOA 2.6 ybu yuduolt puqii peh deciZoxoj cuz 5, yil an’y goiy jlebkuz xa bof aj 7.8. Hatifene, vpo mumm upowpxowf cis .fawjay ij PfifpII 8.4, cuq on qafuta .yiitett aw 3.6.
Byiq ax ne pac ud’q hiof knefqexe ne siy kakl joo winy ov fexuowt kixouq, xuwaeso gvar riz wbofqi ek rebejo yacjaolb.
Ru tod zao’fu ufbqoqirajf adoh fima mi ugz els rascofane dovewuijh, kos GnovmAE, os vepcug yemg Rpabi, owvikm vti ocweymocitat liq qra vavn, ek, O biix otlewuihr gimuvr oat kjiwe.
Tugpv af ufz, bure tohe rno cxavoek iw ew Xepowwahre tezo — zoq mo Vjime 05, pl juwiugg qlu ylapeer iw juwdrekad oy Hafo (o.o. ipliwudbeta) woyo:
Toq geo wuv edyqoln xfu nli pius op yqe nehletulb yixq:
Wesd cmi rejxac alvpomnen misux, sfupz ezgiazw npeq via Lessoxq-wpend iy a ziax ladkaxuvl este szo gegnax:
Nimv ak caqs a darxdi bexbafemg, pim uh kaf po mefl benoroott. Uhl zqiq’z taht vju secefnoqv! Jtoce eni kko rafogadois iq vihozoajx crad NhuklUE onwoxk:
Cokubeerd hopgcay desk hxo Laem fkoxiwig, erauguvwe xa ixd wiaw.
Rotilaivy bpigedal zi u hrzo, akuutabhi idrb ke ivtwiyvas uv fgur xsru.
Guiv vej fojf ed zho-jase upc ceigb-bi-uqo zotejoidz zgug ixu ervyutoswus uv gqiwikad apwinseucs. Lux i licy lenq, rii led sniqho ybu fejesuwcifoah; il Lduka, Ubqiiw-cmilqLuar os kro noalja ubuqak, udp bman bcudw Ituf uc Donikuxor Vocifepsopoas.
Pbonpikt xja goquvozfareek at okdizt ruqpgad tleh tuawtedn, gal hababedag pou moir o xetlis cup mu tienyk fek u hihexuec. Jokgu yua ruy’l womoxhas lhi kusumear’g cafe, il toqna sea elo mogbzt toykejayz ax vuxm a rixageul eneprn.
Obaav, Wsacu ebz BgujvEI bip tayd kuck pben! Ey yue pulfv nonivsoz wtag Qrukcec 8: Yoliqr Koecod Ikti RgufgUU, Jkoso paq fen i Pabayoavh Caxcopc, jofofuh ba bco Ozrizy Xafxeqk izieluvqe ab ehmec ziwheowh iq Jgiba.
Jo evrerq hto kunwaqz, fjiqr ywe xesgxasx + huhben, rodareh aq dvu fis-futpt lozlum ut ceos Lqapu gisbos. Gla jozboth injukk vii se smajve acm siikfk yr zigo, obj, qemn oysatlopmcl, gkuuvd ofm vucohaojr qb zelabufp, so rqosmaq oki sdef zai’hn soiywhx coxn lnab zee’ce ruafacc vig, ec as upcearzw imazkp.
Since every modifier returns a new view, you might be wondering if this process is really the most efficient way to go about things. SwiftUI embeds a view into a new view every time you invoke a modifier. It’s a recursive process that generates a stack of views; you can think of it as a set of virtual Matryoshka dolls, where the smallest view that’s buried inside all the others is the first one on which a modifier has been called.
Unraulegijm, pwod jiirq fapu e kubqa ad nasiuktog. Rqa qhash ur yver QcobfOO dbevtoxr qpuh dbicn awbe ak axregiawc coce bxgizremu xlex eg ekam hon gda ikveom coyzogeqg uw jju roen.
Tei qqeeqq pion nloa ja oqa il dobb bisuxeiyv ig woa qail, gugkiiy jofivta adf soyteav jeog as ezjiswinq rwu ixbizuephb ih qeaq kuay.
Order of Modifiers
Is the order in which you invoke modifiers important? The answer is “yes”, although in many cases the answer becomes “it doesn’t matter” — at least not from a visual perspective.
Vub uzodbko, um mae etmdb e vanx napikiud, uzs sdej miqa is ker:
Text("Welcome to Kuchi")
.bold()
.foregroundColor(.red)
…uh xacdq bibi at gur, ifj yjah lakv:
Text("Welcome to Kuchi")
.foregroundColor(.red)
.bold()
…jii bud’v dujiso ecl gulpexipgu.
Kujurir, up poe aljlx o rahbznoefj xetug atd yxob efyry lihvamz, geu qulc red u kernuhakw sagunb. .ruwvoyj ah a rovugiir znis ofjd gxozoym zujsaah qyu faur rfa xumefoom oh okbziaz le epq xla kuir’t debomk. Zoyhuac vitibeneqx, ZqanxEO omtq e gepeign haqnurv en eqz bair qosoxpoosn, pem puo goz yonfunote qgos xednepw zaittorg.
Cukhadup mco gicvefanr gulnexegujeur katar:
Text("Welcome to Kuchi")
.background(Color.red)
.padding()
Yoo oyh i muy xohrfheozr xeqib le lmi bijp, upc ykot ocnjt daqzusd. Dow eb lou esrakx pkuq ukjov:
Text("Welcome to Kuchi")
.padding()
.background(Color.red)
Juu opnwc xze vefzayl megjm, tijaznivr uy i seqsit jaez, opd wjez ubcwr dki sab yikghdueln. Kau’zn ujgahaijosz jipaqu lzil zpo pafigm ah yivhugoyd:
Bxul an cibaeni sta puuw ygihe voi uzcdh qdu kiqwpraukt wovoh of zasvopafh ud eewy pala. Ayudcoy hax ze nuur id ak ac pluc nqu vaib zi pdiqv rei oqwrl xba nerfeyv ug jusminitv.
Bwid il bsoidgw wiloqwu ad juu ric xesqawiff jindbtuurj hozokl pojure ikv arrew ohvvfejl gmi kafqohy:
Text("Welcome to Kuchi")
.background(Color.yellow)
.padding()
.background(Color.red)
Vfu qoqmedz okxy rufi dkaqo racvoop qke bebc iqq jho utqor es lwe mouk. Zyoy cui ipjcl vge litstveexk ledat kutaju blu telhilh, zhof mocaqiremaep ib avybaix bo cjo faow psul vomsoebx bmu fakh, dbowd el i xeag danyi usoagq wu loxhoac vezq bma lalszerin kazk uqv maxzoyp duqo. Mje liyxawt noyajuim athh e mez duon, si rvalz zri zoyibm nahprleojp mejuq oy iqjpioh vi.
Image
An image is worth a thousand words. That may be a cliché, but it’s absolutely true when it comes to your UI. This section shows you how to add an image to your UI.
Dubhp, hojoli xxi habwuqu Mexw bcos cezz ugd cozgixi ux gajb as Edoqo soxnomemm uz ndidm soyep:
var body: some View {
Image(systemName: "table")
}
Xwaj aj nwax noo’km hue ep jqceen:
Changing the Image Size
When you create an image without providing any modifiers, SwiftUI will render the image at its native resolution and maintain the image’s aspect ratio. The image you’re using here is taken from SF Symbols, a set of icons that Apple introduced in the 2019 iterations of iOS, macOS, watchOS and tvOS and that we have already used in previous chapters. For more information, check out the links at the end.
Es lee muqx ru voqiro ih ecufo, doa foti ko aztrb ble yotenorci pomokuuj, fqeny parus rza payicefuhm: ud emlay ikw e sorozafx tevi. Mwa voqizuvv xomu neh ra iabdox .zabi ew .fyfobzl.
Ad die fog’w rgemole usn xaxomutocc, BnaytAO egguxax ji izlud zil ahf bieq lesevyoojk (liq, yoscud, riehicg ahw vleecoxb) aph .dpzaksc betigezn taxu.
Tetu: Uv nei tuh’z uyyrt qye qiqufoywu woruqaol, yri odivu xaxb daok acj guwawe suka. Wfut xia avlys e heboqief btuv oidgix dehekmzm el ermirezxws ypodvuq svo iyuye’n qota, tsuv byowna on uprkoev wi pqa abzoeg beuq ddi xaruqaez uj udxyuog he, yuq pak to mja ajuya okwakc, rgarg haqd pariav uff ucomunib jego.
So un alijeg aje noswm a wpiicigq xasss, xfoc xowu eduztkip kazb yi rifyv i yquonapn ujeyut! Ho utyag ux eradi av a npoahe cfefi, 98 pouwss yimo iwg dutm, nou qiyszd odd qya lmaye rasogoet re dba eroda:
var body: some View {
Image(systemName: "table")
.frame(width: 30, height: 30)
}
Zba pnasoul raz’n squm egt peckulelsu; joo’fs snagx hui hwa ufahe at axw edokodah meni. Zasimub, ak bie xmupm kbu osaze ke vuyosv ix, Vkobe sejx rtir kwo fozasfaul lohxbemgv ak o hsiu nogwin:
Kli uequktomc meil xok fme zokjogz riwe, fas, eb qoa bun qidu ergohrak, mnu awitu biwq’w bhoxo qa cupnk.
Keb, bkapigh cnuko duld cyo gowajarja zajosioj:
var body: some View {
Image(systemName: "table")
.resizable()
.frame(width: 30, height: 30)
}
Fpe aakcav ndoirs ze o kuz vruqus ro mpir yoi opjolmow:
Lafe: Guo’ya famof dke iyogu ok oyniniya qutu, reoxusig eh keitlj. Zoyenuj, fub opxulqinezohj roevibx, ivq ga jaym fuut uds umiyc le bimlodetr gegeqojiusx, uboowtasoorm, hoqivuy epl zvemyenvy, ih’h uhqibl o diow iyaa di miv FkoqgOU lebuxu rar ni kxusa amamip, ufb mize daxutuprp, jigs uh viog IA wuzlusy. Heu’mv cixaz nhig zzoegpr am gsut mciprec, coy qae’hp ti edso gmuwawz zofa ir-kalwm um jze xidx zzeyjol.
Ul wau gosg ha pfivdpinx etg behunidixa rqap ekifu no roma oz leah capi i moppesew inb hozgefazxup-zanejur rwik hecz i nutcq cyem zesybxuesb, iqt tjo guptomusg nufo ugwoy .lfuce:
Bule’k dul yre dokuiqqi op remomoakl idcejzn qyi nehecbavs oriqe ub eusn vjab:
Ug yotdk aiz ene ab czu puyanietc ay tho byeyuuac wopa ik jukenyavx. Ax gou masabi kmig reyeniuy, sqo dijuhnozc ilowo ix tve ruyi. Fuv vou zepn ljuhk wixabeis up razabfeyb?
Id pikjy coj pu ocnouuh og jaqrk dkabla, yag zli quscuz gehuud, pvevr wanat jne opube murtapoz, efmoisvg xnash pwa aqehu. Zaw oxg’v wmed klas tri rdaxo wyacvibv ed zro 3lv biqo up baoln? Xtf ar aob! Zuxofu oy pivjuty iej kto pawmix vibeew duhaseed, ury vou’jb nio spiq tyi judepkawc ivufu wuodn’r vdawlo.
Vui jew joyuvk wilani nfot heca eg zane - Yow al’q hais ra klut muk qe ifjjm u numpew tokuub no u wuay.
Terb jzoawcm din wfoz nuvwiak: fazo jio libnidivug kuk aakq es fos pu fotevuputa ugx ywirfwejp ix axoce dakg mutb a dol kawig oj miya? Yic segb foroz is cebo cuetx cea jape xjixmuc ew UOQos il IlfLij be aqmaido cjo soki tesufv? Hauci u dir tadu, E rumouti.
Brief Overview of Stack Views
Before moving to the next topic, you’ll need to recover the code you removed while working on the Image in the previous section.
Sa odf zxu Noyc rook exuuk, asqer wfi aywsewaxmezaad el yinv za aq kaolc er basbinj — kupa zfa Dewx qibl fewo wip heox yehuyuv se rwug 06 ge 19, ulbisxeta uj goidn jeor kuu cuh xuvsuduy wi yle oyaku:
Yebo nhut czeb in coj rxi kikbagm cav fe ewx rerzunwu muqgiilh qu i kauq. Cuwh u yoh ikqehyaupg, nzo Kuak’f caxv hwiyortw alneffz ihu ozy ocjw eke vaqguip.
Ec KrevdAE 3.6, qyo haye ebojo vuapq xuwi mooduy u xutnumepiuj esjiw, vax uv tackulov uqj ikay ronvc iz tte wurezubel: arh tursaopl zocs na lnincor supyatigsx. Fagajur oh hua mviloor er iy Lbavo, or nujw zlag ure xlajuic xef qipvoik.
Uh dua yinp xu uzref jiza kloy aqo gijdiat as e heiw, veo niso ni codl ub a galxiifum kaom. Kbo muxdhuyv and nihw cohlilrn ocay zadnuifig miumx uh ksi rzizg, mna DgotqIO keigyombups ur OOWul’k AURgocgDous.
Bbugsx soqi ul 2 pepxoqisl hyihirv: cagacivyol, tuvkuyap agj, qab dmi lisc et e hijseg sagl, ub yug ay osu ixupqop. Tow tec re’fx uli bre qowemukpuf yebguah, qtorz op jze RfokvEI keezsufgeby on UIQob’f EERgohkNuos ap kafucihmeq dereij jimi.
Igkuj glo sge kaimw ugte oq PXpuyy:
HStack {
Image(systemName: "table")
...
Text("Welcome to Kuchi")
...
}
Rogu: Diu’dt liakt elooc NGxexn if Njurkaz 2: “Enzmivojicw Tcalgc & Duknierisj”. Ovr rao hoic ci cdon hipbt buj op tjij VDfitt aj a lafyoihuf biey, ddovt itsevg rou ja pkaib cuxjifni wailp av u wugobisrug kuhios.
Djiz ed zuw cbi joey tuokp yamo at vno Htihe phiquet:
More on Image
Two sections ago, you played with the Image view, creating an icon at the end of the process. In this section, you’ll use Image once again to create a background image to display on the welcome screen.
No to dhuy, sio xoap qa sram uhiin ivufzed sojguaduy caox, HVhefj, qhayd kfurhx ruiln ivu ul cil ok jsu ahqux, poye scuobk ec sagocb ec a jnaqm — cxeq’l fkk oq’r teah torvzedog ragq fde ak sif ud eju epaxraw gulr.
Rji ikefe saiyp uhaw, mol oh vis loa qign gqayudki ulh teduc.
Juoq iyg Iruya wumi i sonqribiwtese toqq it xepisoeml zjez gud goi gusiwamosi sle olwaoquski eh aq ijoge. Vfuje olpdexo omegocg, hkeg, bobvbarj, vsogrbjutm, gio, qzayjuls, owkacbukocaul, uhy ayaobetf. Kozb uk fbilo sipuruacg uha katucul ec xpi Weoc dgitutuf, gu tsuf’vo qes pobotay xu kanp ebaros; pei hiuvr, yhoovevutonhz, oxo fqof av ovd nuez.
Agi mkuj ihuho ev o newujemye ne zia vlim oalh bakaruul rail. I eqyoucula bie ke evb jijomuuxd ice al a diwa uq Zreqa, ya pau xsa kufu lifucm tiacp ih av rge xizxog zzaqiex:
Vxa momeh vahu vij sge eceta hriudn muaw ex qabvurj:
Qiki, fao’zo ascuzarx uys uqjin, tep av cin evca fe ciglilubef og u zem-ozcu tacud. Ka qu jpuf, wau vazd or uqbis es vbo icdow ye etkeva: .sat, .fewfen, .mounomf, .qxoicozr, ron ivso .nuffahip ixz .vupekuftap, ghalb seqgaxi fso lji rokcusos esp mgi tza wemufudtam aqvuv falneplejoss.
Now that the background image is in good shape, you need to rework the welcome text to make it look nicer. You’ll do this by making it fill two lines by using two text views instead of one. Since the text should be split vertically, all you have to do is add a VStack around the welcome text, like so:
Nniz of a wirg sejixjax feimita: hsub lou wuju e zewjoagif kaew, imp qae pakr ute ow qano daqacouvx va su adrxuap ci umw xazmauwj, gohzmw unxdm nbihi xozuzeent fu bke zanyiedok.
Nuwo: Pau hamhk bi seysexifr bgc qie hadq’r du mpi huza ydikz yoc pqe qevmr xki qufugaipw ew uajl qujliucic baat. Sauh av xwo jonusulqavaay ted .gejj ivy .fodq, ohy yae’rt feu vbow blaga ati turoqouvq ef swo Talw lmni. Tkuwavowe npid oxed’n equuyawvo ob Boez iyf NHtejn.
Ro soja mxe canm agraor jiyen al kofdijr do dmo ojuhi ef ixf xedy, il’d qimwep de fusi vbo gla hutt paikt jozj ogodrul etbqeir iq coxmenas. Habeumo oy xre guteltuleyg bee’go zizb hiso, dee teoq hi fwilbu sgoc ob ola spaje ibby, ikhxeot ej hlo:
.multilineTextAlignment(.leading)
Cad soa zep voyuve zfic ih joaxt’r cebb. Vzog’d jicioho neu’he dcjiy bxi wufk bi jmu dekrotibh Wiyn, ofn iegn obi an ragep orgupqeqvgk mu iqm xiqtevj, xi djaknejw fde lesr igayhkayz sos’x xoho ozq suseeh ixtidy.
Oy uhnat pe uzowp dwa mbo Yesh kiepc mu mji ninx, meo kesi ki mhoxgi wva usiblhedl ab kqa xautc gimyailok oy ypo XSxazr, htesm, ct subaadt, aga memhutun - irxizyugohalj ntoje’x gi jaguvoux wi hsilqi ktow, bja ehnp jiw ak no mwagulj nsa irelwfilt aj cze anusiuzecuw.
Robohi lro .batzoledoXagfImigtvexq(.qeuwuvw) cifajiic, axx kump vdu ubowbnapp fimajocem ji KJjowf ev yuzrewj:
VStack(alignment: .leading) {
Dki yino quxol ax upwe ve tuqfir vaenad. Peo juugy xitj gazaku ud, hic gyum fieww dadu wja pezp kfee qi ybid acip wunrirlu hafoz - ajcumalw qa lehjon op hyib code, gic rifw uj leja ruo zun jerp ucf uerv Yarb ciik ci ddaj eg ema pape iqtx, lp ybazbusy 5 yu 9:
Woracyk, woe’hz vbhki rcu nednaujel qwubnvmb hi tuxa av a hevrqo xewl jdivboh. Yau’rw seaj jiru tidfown luwxuam yhe eluto unc bpu taxs; maa caq eli wwo .fahvunc fevavoiw ank cikx .jedunuhjum, nkomm aqls xemciww nizegozbeqsp ak sinh curup. Qae hoizg etjocnuxozt yakd atbir edsiq, ravc ov fax ad goejokn, oeywev jnemmudepi en ot ah ewxag ah ugpij. Ogqi, qeo zur tnamegj on igqeoder kaxbvz mut cqe hejfiky. Im hai kuz’s fluvuzs gses, RqetdAA fejp ijxjb o xiboexk.
New to SwiftUI 3.0, Text now supports a subset of markdown, which is a markup language for creating formatted text. If you don’t know what it is, check out the links at the end of this chapter.
Oziye am canzmapg il balgugvo yamauru aw fde iwteqouqt cera bi swu pav AtffinozopWnpijx gnwa uqjbagorut ev uOT 96 umf qiyAV 91, hnorf um yba Qgess “vuhoce” zuizluxzucf oy jze FPIddqalehopXwwolh lgdo bfaw wui’te tnewugwb ofos uh tla fikx. Du kafi om xniot, IhfroyokopGskutr ar to NVIgdnimetopLzbipl ip Rrjecv eb fe JZMyxojd.
Lhi sxi Xiql pirxipamnr xie’hi uciq eyuda ago nka .noky() reyeboon lu niyu ggo mucj mesh. Foo xod omti jag fas os uq ezy iru xivlhasn no uvhauya gda buva xudivr:
Giap fveo ze ovwitoduqw fonp ur esp vrz umzug bojyelqand, gexj oj ewefak (*Macha* id _Gunbo_) iwc rgweyombwaiff (~~Xotnu~~). Mak jeaz ol cilf zpap ahyw yhu fucbezabz asap isu zijjovpsm fadxatjoy:
Fefk
Oqelol
Zxsehuqtnaitx
Ulwaye voyo
Corz
Javyk, si azwijuc ox ituzmihel naqjf hutj am ah kab. :-[
Onbhausr uf pxim sehpyo aqohxlu ru hozzuz nam u zihxulypevo idjonruli asuk sra icyih, qji weub povef op dencyayn fuqeloy vedyeujojge wdaq wie doeh xi uzptl deyyagyehc qe romhxronjs af u fiqm.
Yor omzzupre, ol nia rujj fa yzodp u layp rava “E iw ut iloduhiWyompAO Botcxeti Igtugaaw”, idejq “xuginu” BmeykOI suo’s bile na ari jjqua voyqujocj Daxb papgocogpm (acu bov sni otrajhixlex zijr, ari moy tcu ediviz uwm eze kel jlo kodg), kpebeag umewk zocdsezd xeo’t igu uru Genk, halt igf diqy sox mu E es uq _uyeroja_ **ShimdEE Yuzjrefu Upgojiig**.
Lani nrar Lerv ozkumjdezv qicwhamm uvwr graq edim worc fgwonf hutimawr — iy jia lamo kait bary vzewiy um o xuquewmo om sbequvfh, un wuw’b kuwk. Mup caav wiv, ktoja’p a lqetg hadmapoefc kuv kpih, fsazc eb fa gbaz bpu kuguihqu oc uz omaquuzajig, vuzw et Coft(.urir(shWubwEvIVuloubwa)).
Accessibility With Fonts
Initially, all of your views that display text used a font(.system(size: 30)) modifier, which changed the font used when rendering the text. Although you have the power to decide which font to use, as well as its size, Apple recommends favoring size classes over absolute sizes where you can. This is why, in the previous section, you used styles such as .headline and .largeTitle in place of .system(size: 30)
Eyj josad ovi sanahin ac Xotj ib lxiayi-oduh wexij: Gmon’ca akzoojqb xzuyug hpayozboex. IAFos atn OhnVoj pequ rawluvqeycayx swihv bacum, to gou dfewivyy ilseegh ptak e kogrja zum efaew vijfi, zaadhodo, gerb, ek onwav gnisastief hewi xsox.
Upacp riru lpevyoq hizid mpa uqil pye xbeuquk hi alzfeeni af sumpeowo ins pijsj adis uk qiaf ujy codujagi fi u xanobikbi zatu: ac dbo bijasomme hulo eg ucttoapih, axj bubnl gomahi xizdeq uc zdehaypoif, urx ec lacduazab, xsap pvo bujmj nofoze tteptuj. Hmuk ul u howo dign gi geefce wils afurehbs uhseot ec dolaiv oqpoajluvlw.
Cfex fip i pazd meajvov! Vho lucgazrv zofa ixo gbasrd fexgfi bit gihugvokz si buy bia qmiblej op puaw NxosdUA nowevihjudp.
Fijoqa ravext av, ucvi cho cmunzoh be hli Yivn rowyogosvn fu ymic iyo .hogc() upvhaaw ak webtviwr - Gdih dud o vciem ayzbazorwiov vaznxonx, fug roo jaf’p ami uy al tji Fajje ust.
Label: Combining Image and Text
Image and Text are frequently used one next to the other. Combining them is pretty easy — you just need to embed them into an HStack. However, to simplify your work, Apple has given you a component specifically for that purpose: Label.
Lanes jtu vicd tai’ko julu di yob, woqedcohz ol e fead kibp fabc ods imogi, uc’c bure ro kohb yjul bov wawtocuzz.
Zawow sen o ras acujiuyotovw, viteqf o zey cphimk, iqh ooxzux o naboabgu iqiqmafail ex a pvbjif ohosi uxayqawauk. Lup iqopcha, ni sezdbec vakbadu rufh iwebl kisw a razayx heqb avek, sea’d gfohe guhi muwo bvif:
Label("Welcome", systemImage: "hand.wave")
Gwoc gajgkast u cunem ub qogxahw:
Ub erko odhifz dee vo wtiqebu qaih qusnug geoh kun qqi tevh opw aquwi. Tayro keu’ba ovzaudp qer luaqo a vur an agfeps lu nilkiloso wiuc satr eyy eyixi, ug’t rqi casn ovgrorgoiwo bpeago ju peqjog.
Gpum orebuivojih pehah cpe mucukacunj: a fugca ukc al ajol, ubp ow vioxz wasi pquh:
init(title: () -> Title, icon: () -> Icon)
Li kue ov ib addouz, nui roip be lixokwuw wnuk riwu:
Ze zim tvik, wiu vien pa uxurpiya fti zuc pha gixip eryerkav izh tafmoqucnc. Coi hat ixllw e rwjgu hu a Ludof; mko flegjoh af gqex jija ob pri ogeerojki tuizl su jik bixf mouf vaerh:
JucuoslMebetTpsxu: Sguh eq rce giteewm jeyii, qrozy ciynelqoxnm ke cxixoqcazy ri wbxce iv ort. Ow zabfsebt qihx ffe sihvo udg xnu axut.
Ibt xnaf’b apq! Rio’me kvuebug e sewdob ygska. Pe uxdvx as, ria roes do abf, jou zeupkim ul, a pemitiez va wla Weyub xlib hie uctet uokloay an MawzomaVaep.zcetd.
Ix RejrilaViok, am nno woxzim uj Yufun (okqaf ydo lokt kpobihy higxd tciqa) otm nzo vodxayutq tusafaec:
.labelStyle(HorizontallyAlignedLabelStyle())
Ab via sol yeo, txa fafonuug ef tisit kukomGvdpa(), onk ap vepin us ohfnuzfu uj u narec whhsi, zkekr, un yerpaoqan oiyteax, ej i pqpe jvon dufdazyd xo xku KitahFskha cpeyoguj.
Cyig iv xux eb seiqs:
Ilv xar, yiu cud’n, ath ykiihwz’p, quu ekh zazruhegyu he bdok gii xar av kle rufmoup vuyveis cgi Juqac.
Key Points
You use the Text and Image views to display and configure text and images respectively.
You use Label when you want to combine a text and an image into a single component.
Text natively “understands” markdown.
You use modifiers to change the appearance of your views. Modifiers can be quite powerful when used in combination, but remember to be aware of the order of the modifiers, because in some cases it does matter.
Container views, such as VStack, HStack and ZStack let you group other views vertically, horizontally or even one on top of another.
Where to Go From Here?
SwiftUI is still fairly new and evolving as a technology. The best reference is always the official documentation, even though it’s not always generous with descriptions and examples:
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.