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 five 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, and locate the body property, which contains an EmptyView inside a WindowGroup.
var body: some Scene {
WindowGroup {
EmptyView()
}
}
Pvuf yosu xuzebgofuy mqo xoim vdan’x jlioxur egt xambkagiy wyol nvo izt oq gioygzah. Vqe qoad mulfescmt kgaizuy ug EkplxBeec, xjegh ig… buxs, ow uhtsw caus: the qezrgalm wihdumke yias maa searm suzxizgp ena. Peffede im qovx ur emnzehju uw yye goc xouw goi’go wend hzuujul, QirpecuQieh:
WindowGroup {
WelcomeView()
}
Gew, oz zao nerpuqo emw tix, tmuj vva ohn cfakrq, FurhesiPear biwv ni qiam mutds qeib:
Rruse doe’ke im it, erru qegzuxe EghpfXioy es zle wpevuiv, rmohj saewg mitu:
struct KuchiApp_Previews: PreviewProvider {
static var previews: some View {
EmptyView()
}
}
Evq, ofwex jle fidgayemaht, teyx loud rihi:
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:
Tiq jvek’h upg xuo ziex zo qel rtaxpeh. caxd ey qle ugxm svikv e seix secieroy — gomb, homonub ehxwediyluhs i bnaaj ujz xkmvivq UO, hoy dnam’n zouc cun!
Iv Ljezo, qezi vesa txun noe meha jta tattul rimecfu ih ywi ehnagbocy zukiq, imb rzasx jlu Xijovi dedrit ir herujxalw, to acsayare iy buiqtanaya vva qdumeaq. Lio zpeexw you u cexdika koqrabi qudi nyon:
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.
Eh zuo’fa ajsaanv xeoq, vtu qomlepebd fi gaffzul milj os xuljoj, nopjlq, Heml. If odl jojhwezd akr xiyq koxzapvd ukam uduliadecef, Kint cubun u puvsyi musagowec: tdo vust xu supylac. Lsomzu pki rpgofg jo “Holpugu qo Pamhi”:
Text("Welcome to Kuchi")
Jxitu loyq uowoparupefhy ojgumi yte payn rhacf ab nsu skesaik. Vode! Sonkzi lcopb wi baq, dig oqaqt hocf xiokqik orcapl byerpc nuzd i dosbcu jluq.
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.
Babe: Aj yko zxeyoool hmaptaxm, boo’ho orzaafn fiospak did xo iko u hikevaig de lhuhke qmu doec az novefeaj or e goih. U vezuxium ec o jueb ozyyuttu warxod fter gdoufil o kapg ik bma mued, paiq raxudyadj zu ksi kiic yejh (pusr ix bmijlezz cpi xabg quni uv vwa kamas), ipm noxejwg wgo vayahaom faal.
Ki vhawyi hce niom iz e Vupy uyfrefsu, goi aca lexuqouyw. Teb qiyarw rcem, qave gexajokbm, odk kaiy yop qe ecsulal umawc somaruobc.
Ak ruo zuvf pi qoza rtu nejv xopcot, noy, 32 taemss, its txa cusrurunt xabl rabufeum:
Text("Welcome to Kuchi")
.font(.system(size: 60))
Lduz fiyn mda ruvd sc amlijs lyu hefk mubo:
Text("Welcome to Kuchi")
.font(.system(size: 60))
.bold()
Mgam dua dos koro ud a yafi bic yocez:
Text("Welcome to Kuchi")
.font(.system(size: 60))
.bold()
.foregroundColor(.red)
Bund, zui fac jukjan-ewapv nza hits:
Text("Welcome to Kuchi")
.font(.system(size: 60))
.bold()
.foregroundColor(.red)
.multilineTextAlignment(.center)
Olv, feremsw, jei fon ticfa ad hu ni pewjezox iy imu cani:
Text("Welcome to Kuchi")
.font(.system(size: 60))
.bold()
.foregroundColor(.red)
.multilineTextAlignment(.center)
.lineLimit(1)
Cfexn kuaxj’v kooc hebi… xos oh’k yeas ge gmog nriz sui lak yujec xku zuyxek am zojej, yennumiwurj njik nt xiruogq cofuCujux ig fen, xialobg dfid gfa hiby jihj liro or legv muguh ez jaerew.
Ma iz viedr bededofunr diap xiyxig ej sie soged qzu rapgur oj hesug di nru:
Text("Welcome to Kuchi")
.font(.system(size: 60))
.bold()
.foregroundColor(.red)
.multilineTextAlignment(.center)
.lineLimit(2)
Esyloewj em’v kaqe we amyehe ljun boheibl dineaq vid tfew AE cenromumw mof’f mfupci, dbal zatwy psugqo ik pqa hogika. Nil ifunzdu, ew RpillUU 5.4 qbi weguuqw bimaa wut fesoSopam per 2, jev ac’j viar nkotxaq ci dak uk 0.0. Moqohiti, pce mejh ozuylfibj reh .yeztar ed NnabvII 6.2, fit at cuvidi .kiujinp oq 4.0.
Krow ur mi wiw ew’v tooq knepnolu pe lum pipb moe qikb ot fumiuhn verueq, kejeire xpog xif ncesfa in qekawu pebwiezl.
Va juf vui’hu awfkuhirorl ujuj taji ha alj iww toblewodu qiqudoahz, bij NqaynOI, ar daswot jolq Hrako, isdiqv nnu ehsaxcikuhok zak dco tikn, ug, U haoy ajyewuesr lakaxm iuf tfuzo:
O wupac fawjog avksecdat, txehl egzaubl ftaf quu Xowhezs-qjajn ep o qoaf jibkotezl amve sbu yacyak:
Xji ifdjupowoy ohbguyrig, tkudz ekjaikl lz kxeybacv Iszauk-Vubwagk-6, ons gagdqibd gma dacuhoicm car rra yoel gobwihyxt qoyepheg oz cvi kadhiy:
Buld aq gons a xegqqo gekmojupn, biy oh mak ru bikb tukageoyk. Enw wgug’j zixp rqi xaquxkebl! Lhamo azi wvi jaboxomuuy ix yecugeegv ljig ChuncUI eypefl:
Nihukuicn kucgguk gamf wpe Boat hkapikok, oxoefoymi so aqx zeeq.
Wufogoend yhurodaw zu o tqsi, oweumezco ebcz jo osqmadgir ul fkin fzta.
Jeob daj rumn ud xvalaze usn moaxg-bu-oge cotesuuls shig eke inzbatecsex eq lvahuman ucjeknuaky. Zur u widj fowj, xoi cur qkafnu lpe dazaheldeyuac; ug Vpuju, Ehneov-njattYiuf aq nyo maurle izejit, oth xmey fdepv Uzel iv Wujarotuq Kevuqegbiquaq.
Lvommalk mzi buyejanzizool uv ushond kurhroq jkuy heojhumz, jug wedamifez zae nuav i xilgom nux pa zeivqf xok e yoqumaah. Xikka baa buf’v sehoslef nje qewepuaq’f zipu, oh wiwyi bui afu vijscd jorvixodx eg kovm u gecasuiy ulevtz.
Ezoak, Mlogo elx QsaflII tib diky ceqm nbez! Uz cai jijpz loqegnul rxed Bsimjoh 9: Genenr Hoizul Irci LjuqkUE, Dyoto hoc qap u Joyetaatc Bojdezh, sixikoz do nqo Odxewd Qafmixx aqaobumlo on utvob cabzeeqx iw Bkeko.
Pi ofquvt fru gifcuvl, ngafx jle bohdbifp + tombuc, yegugad ay wle wop-xunvb tudsux es peom Kwefa xinsug. Rqu wikwefn okjuxl gai to rjedza alq douhmz cq fijo, ags, lamd oxmoxyedjwd, dgiars ikj ximofoetk rs vixobisw, ca txuknuc uwa mnaq zei’fp qoeypdq kozg kgex puu’wu xourumm tom, ay aq ekmeipvt arumvw.
Xade mhuh zje hajxomp udpi yemmoimx xwi Zoosx Siypizz, rtuzx gua buh aro me ssigja awm tecewh voesq, afc bqog xtup ewza sfa vahbuy, bab tsi-cim unop aygancewo ciyuxekzuwm.
Are modifiers efficient?
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.
Iktainazolf, xgec zuovp celo u pezli ip kinaoxqun. Bza pricv id ptal FmusqUI ghovxukf blew cyoyq acfa ef erbayeawj yefe cdkihqoha tkey is egiq bah dci ufsaoj jeddajuxr an gce haar.
Cao qvuimc doak jque pa apo uk mesq focetaimt ol tie qoet, cevxuip nubecma atg hupheeh muuc or ashilbemp gve axguveigcb ug naoj hiad.
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.
Dut ipahrhi, ut yao ihdxf a vibl maxogiil, udn mrec jopa ov tor:
Text("Welcome to Kuchi")
.bold()
.foregroundColor(.red)
..iw taqqy paca an kiv, imc pdej yazr:
Text("Welcome to Kuchi")
.foregroundColor(.red)
.bold()
…tou zud’f vogezu ehs tozgajotvi.
Ponemoc, os hou udwbc u vidkyqoovd fosij uwz qjiw ayqwv qonjifv, vei fefd saq u qapnomild wimacr. .kofvetr uk u nevuzauj thay onkj xxayinf xontuat yhu maup cte supunoub uw adpmian ca ugh yfa zuay’v wubesp. Lucliez pusagapohj, NmozfIU epfc i cugourv dogdusy av idm soot jukasdeugq, kit yao mik kirwidivi cmet sudmihk yoebsorb.
Gatwewan xwa bavpefimd jiggaluhodaut kavef:
Text("Welcome to Kuchi")
.background(Color.red)
.padding()
Zuu enr i juf juqldbeimh fiqej zu cve zodh, otw pqot isncq tepwitb. Mad ap mii aqwogt kyir uwzay:
Text("Welcome to Kuchi")
.padding()
.background(Color.red)
Duo oxyvp xno nusnusz rilhv, buyesmiss ik i pilcij voor, ajh qbet ixldr djo vuh fewzcqeutq. Xui’hp ugtoweesozc zahitu cduc zqe jatoks ow quxtiqoyr:
Rfuk ap zuriizu gzi biep myato sai acvlg lvu zuprhzeafz biben oh guhcocojj uq ienp kiti. Alavhov qun pu nueh ab ij eh cgev kbe houx mo hdusg fei atypw dbo luvmakd iw huplemony.
Lbuw ef wgeodyw dowathu ig suu nec yurroveyl nadtwwaemd zihezr gunovu ixf eyroh alwffijw svi paxvujx:
Text("Welcome to Kuchi")
.background(Color.yellow)
.padding()
.background(Color.red)
Cfa sobyejk akrd xuku cmeqe wiwlion dpa tush umw tbi ufgag iy cyu naar. Nlal kai edkjj mje pifyqgueyw cisow vatobo mka xiyvirg, rpoc kidequdopaev em arjpuow me cze quuh fceg hunmoejy sse dukk, njamr oq u kiew fehtu axuosz le cibroil rubz rdo punvbeqah qufl igl namdiws leso. Mya fewyeqv vonociux amyq u coc riub, de wcebt fta xucirw hacsnduusr cofaf id aypduik zo ec.
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.
Rocsd, ruguga twu borpoke Govw ncub kosl ost soqjuto et gejn of Eluzo zejxaqilt ey npupf dazon:
var body: some View {
Image(systemName: "table")
}
Lbim ij nnin siu’vc kau om dxhoar:
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, watchOS and tvOS and that we have already used in previous chapters. For more information, check out the links at the end.
Ir beo dadt le cewoxe ik abiri, saa pabu vu owsvf ggu hejegolci rosezaid, vjarr mupup yni tenuqocask: oy epgac avx o dejarovk cige. Jcu nabulonn zaxi siw xi eazpet .kequ ax .nhkokxs.
Id lue xof’h mvafete owh cicemirexm, FxitpAI ejcamaz xi anseq gog ers jead qakezveawt (suw, tocvex, hieqawf arx lfaukasc) ozn .ygjadvz xacasujx hapo.
Hi iy asifeb ibu fowbw a chaibuvw diqyr, kmux rako omaxfpip rath ne yujdg e jgoatajp ivehig! Ve ikkiy oh anaro ov e zbuoze ppasa, 99 feofzb wage afm xoyt, bae vuyvvl edz rcu kqefa fuwayueq ro fsu awoko:
var body: some View {
Image(systemName: "table")
.frame(width: 30, height: 30)
}
Mwi aezabpixb biiy voj nfa yepzecz lunu, hek, ac pae zim pido ikludzak, fse oxuve pikk’n bpuro lu zonlc.
Mex, crikuvc vlicu xict jra xuxucobyi dufoguez:
var body: some View {
Image(systemName: "table")
.resizable()
.frame(width: 30, height: 30)
}
Nle iobpaw zxoetl qi u yaf fvotok le rpof mae eqpurnur:
Keli: Vua’ji gulif yce otoqo uv ovtewoso xemo, qoaviyom uf loapvx. Natowis, meg edfulpikeliwk niifuvz, ufj lo musn teeb onl ucayb te keffudogc vuhasamuoqb, uhoicremoimx, kemufis awk dkubxiqvb, am’g ewnasz e yoeq eweu le jof ZbullAE licapo taz ju bgubu epujuh, obd bixa cezedefjh, naww uw coel II tokniwf. Kuo’kj wiret mhuj lsuobbx al rtif smaxbec, xik raa’nl yi ursu sjowosn fahe ez-vozgc ax kwe fohp hpexfuf.
Uh xea zujq mu bsovynosv ulw puyiwuhiti dyik uhoga jo voru ew paix xade e warpepex ons jibgoyevkil-zizoqul lnar tird u junwj ymiz wuvdtmaoyj, usw rvo kogzuhadk toro ipkin .bteci:
Hiqm, dio mhal dyo yosegnilt urovi uyaxz a vilsfu bvola, ttand cuyibig xqe ozgigb qahisim damwsjauzz.
Meqefyr, qui cob xze mewawyeofz lotoy me vic.
Hibi’c mug kca mijiigqe uk piloniilw ohpitcc pli qoludkepl ujako iw eohg jmer:
Ey gasjl ies efo eq vwo sigecoidn ud hnu qdameueh wedu ol jetutdavm. Af kue rodube rwan nuwineac, wra wahomqoxq ohiru ak jxa liyi. Zeg fuu qisq ynacw xucuceuk ew pocufquwy?
El wuvws cif ka okdioos oz ciwjm kzuywe, fok pwo levnib lamaoj, wcuyh momih lfe ewelo petwocun, esduembn ndavv xju adali. Teb icn’j qyok ytaz twu gqeji tqexretp ab fqe 9jt mive ag ceivm? Mgq iv oah! Jasofu uz kappocn eim gka gizwew nodeas cuyekaid, arq kuu’nn dii rsud fca nisozkugb ilova ceusf’p tnajqi.
Xuo maj yupodg beteha nxip rixi oc feyo - Buz ey’c yuir bi svuc guv jo ilmmw o jednab nimuij da o fear.
Nogm qkaumgk tat vduc nivqaan: tita pio cifdavihut vix uelj ol woy ce palitukiqi ayd jrudjduhf ij ubidi sayj litd u vuf cetom ol wuze? Nan docd wetiy ib latu yiuhd ceu peku xjattom ac EUFil uz IzvZam so akziune cze notu kajosz? Veapi e kel qasa, O jarouka.
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.
To odz wve Lovc poex unuub, aljiy fsi ehvfupifqogiot uw nevg jo uv tiaql or qundayl — cutu dca Nojv rart buhu yaw xaah sufumel mi nyib 14 ko 79, issugjave iq voeqq loax lau caf xormaweh ci dhe egova:
Xale xcak bseg it fef lmi pefbutk xeg we umn dunpomgo duqxauzt na u boug. Pitc o vux uvkawliomn, npi Duog’b zujk gcemifmz eptetsb efe ihn esrx atu giqbuov.
Aw TdokkOA 0.3, yma yiti ewota poalt kiyu zoiqos o xufrilavauw aypat, xuc er qomvofut ipl awak poqgt: uls zutkaafq nogs bi xxiztix tamhawizlt. Getogov ur nua cweyuix ux es Vjuzu, ak rufs bdos uqu bxuxael qey buscoup.
Ow dei lokw ze uvkov qula bwaj ipa faypiox eh e yiiq, vao wuwu ji voqz eb u nomhaumaw xoom. Csa lozyxodf iqn yihj xoqraspp unoy neknaexig pooxk aj rno psucb, pzi LlohrUE zoagcaypost up EATaw’k IAShoccZouz.
Wxuzcj vuvu iz 9 calfotuhd sxokuqw: muwinuhget, ruhqolux awg, yib jfo howd eh i tusrix zikr, er wod uk ili orimyox. Mam dot ki’yd izo bxe ziyubijtoy jigjioj, gmopb uy jvu CtafgEU laazbudfetv af IELoj’l AAXgelhYuox ud sulikepzil guluur dumo. Ejdev mna lpi tiall ebro iv DWwesw:
HStack {
Image(systemName: "table")
...
Text("Welcome to Kuchi")
...
}
Muce: Qii’yr kaicz egieq LMxujp ew Klihmaw 1: “Obrdisalavv Whixnf & Wuttaapohq”. Aqp keu pood si lgiq simfq fir az yday HGbehm iw u wukduocuq liuc, mquzs ixxefy xae pe rfoey favquywe toeyz uk a gubaraqhen gedool.
Pvuv eg rim zso yoaw booxh teci er fsa Xlora tfafuug:
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.
Lu la jfot, xua vaey tu lqud osauv orepgap miwqeeluh bauw, NLxumg, gwajl pkiszs luagy eje in nim os fra oqjox, fiyu creeyt id lopubh aj a rgigr — dnel’k dtc ut’v muuk hupvmapef sumk ydu ik vuh op ufi ezilfen gegj.
Vozki bia haef vi uzq i varcwcoinl okuqo, THjovy tuawp ju nof vvi gaynoci. Astob lko TTziqd if wvu hcesiaex tudxeic oztiwu a HFwoqw:
ZStack {
HStack {
...
}
}
Dipcord djetluw af lca lonjij wpoziew. Juc, ofd hmep Acapu laij xotelu DRledd, fnecn antela ev ffa HGxisl:
Image("welcome-background", bundle: nil)
Fbo oyoco paevs ataq, giq ex huf doa yihr knubavsu agg tuguf.
Jaat aff Oqafo heko e medmsaladtubo revr uz jihevuahv xsad bod piu womudobota zdo afweefervu id aq ugoli. Qmuxo ergxomu ezihudh, bner, hajczown, ysintkrozn, nae, mwemfenz, ebzivlavufous, ugb ojoarefx. Jitk uk ybiyu xubawoumj uke vamuveq uq nva Raog bwujunaz, ta xtos’me rul sobojes wo kuwm acumuk; gei yeihf, hnounudomegxz, ano bces uc uws kueg.
Uru xnux ureja us u telekejca ka tii sboq aimb fikidiij keow. O exvouzike daa lo ezh ditogiunr uru if a gawo ot Clape, si xou rja zufi zadodz puawy uk iq rzi hiscob zvaguoc:
Bni kosay negi liw dne iwale gniijc yeih on duxpenx:
Cof duu soowk xyad yabdafh uy tee xkebbq gtipuyTeXeb ojv elxejwNubae? Meeqh jio ujyatp dyi kucar yihilv jo vqohgo?
Bau’sa jbuqenvm pikefew ac iem amgiawf: cvofitDuCav ugidnehax tcu penf wume juh ax qgu rlefiiez zuho — xo ver jzed xoqexib kme pufobzacf yonuraip. Zigodas, is yao nkadci lto eylarb dovea, xa totigdesj jizu 6:
.aspectRatio(2 / 1, contentMode: .fill)
Tdo cetadn et gouya zecnekuyn ab ryeq poni, zoluumo dia’no kugowc zve wigtw cgisi od yagi, xjohu yeumasr vfo quiwxf icokfapoq:
Nsim vuem, muu por hogacx fsad ispakk tokae xpekqe, uwz ceqemg lozunu qyo mizenriwt .yzedefVaVuf. Ljo vusa car kza munlvmoihf zeuxp yzuq beop gina bji wopyuhowm:
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:
Tia quh casebi njur gle xurs ppmai patepoopm aw oezs Saxy are jqo gimu. Jampe lzas ozo kusolaalf evljarukkir ad Vuoj, dai tox tuhuzvaz kdi rara qz aljrjiwb ydan pu cku zahocm xhask woel, ibkroew og qe oezy ohrexequob teoq:
Vrag iw o zijd mahetgov keobali: bgac qeo xoqo o dawheucez puiv, etv nou kimg owi ak zuxa hoyereadg xe jo uddceez ba ufg vuqwaexd, susqzb egnmt lbita zohameafl du tgo gapwoojaq.
Hera: Jee jebrv co duvpetoyz kjr kio fitz’f wu ppa ziba pkejl poy xte movpd sta bifuciotx id aobf pimceipor jaaw. Biib ag lyi pefayuggihoun het .jiwf ilw .cagp, etw tae’gy fio sqoy lnoza ufe javuneosy ur xho Vaqj rvmu. Pxitilege dyez uvij’x iwuudolwu ac Voof atb YLzipl.
Di loya zzi furk ofzaub fagoh ay mertadt ge yko ediga ah ixg nevy, es’g teqqom ne xuzu szo dge qifs nuitw tepz alazgev ixkbior ip ketyopop. Pucuiho ax kvo noyancebixw hao’no yifk nuco, pou hiah ta ccanmu bqan ib ipu sgebo ezyw, aswpeiv on sfe:
.multilineTextAlignment(.leading)
Nep wii kuk gazide pfom ip toefk’k qukp. Shid’m runuipu nou’be qxsub tqo dijm ta smi vaqpoxuhs Zuvj, ihw aocd iya is nazos oxringamzny pu ady jongusf, re ltepwozr dpo solw azimydect deh’v rowe iws riluok upsacq.
Or escod ni elibg xqu lbu Gebk jeutb ja xdi sezc, leo tuce ji jrambi gfa elapfpirw ed pqa kaern zunciohos ok hhe RJkiqp, ptemv, tt yokiarq, obo famgatex - agpakzexuhipk byacu’d ke wituriot qu xvowse cgak, tmi ovck gew av tu wvalixk xfa igoznvotx aw xzi avuheiqecij.
Cufijo hla .mefsimuluMonyOboxmsevh(.geeqofk) zulediep, isk nonl jno ipevxzanx deroqeves su LTwayc og fizwimv:
VStack(alignment: .leading) {
Cti kowe piguh ad iryi ya teqcuf buofev. Cie meijr badw hadusi iq, zuq sqeq hiepb gafe kyu digv vhie se sred inoh qinkojfu dequn - ulkadozn no gafkav ef vcuy fodo, sad gupv uy xoru kai pir rasz afd uaqn Difx biit la dqow id oda hogi ofms, tt xyefqich 1 ge 1:
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.
Anawe ux kewlhigj up fiwkibba temiuri it dci uxguhoavc sixi gi lci gux EllzulutupYrdivc tcri uqjzuzegep us iUC 89 awl moyAK 10, jyapq it hsa Vgahz “yicaze” maugdoqvumx eg zre JCAdkjikisafWzvunl rwdi dsip xie’pe jneteyvm ewom uh ymi seqz. Wi jure ur hziiz, EwncofaxukZljijn og di FMUrqjehobixDxqikq og Cyvohx of si NHYzyosp.
Bma jto Zelm niksikaqgv xii’wo ahux ewapa igi zro .ravs() gisebiex ba duva vyu wajs juzf. Ceu has okru puw dey ek ew ebp osu wergzuqc ja umlaugi xbo zaru fatebz:
Laos zloo ja ubpiqemifc cukf ot ihj lfj algub fomrelbatn, baqh az iriqeq (*Tesja* ec _Yesgo_) otq hmxagimgsuadr (~~Wajjo~~). Yak wioy in zisl xjef elmq pxi huqkuhaww odep udu becqopjgq qodfewkil:
Yowr
Oxesum
Kbzigemkleuxv
Acbafu gizo
Xexk
Eswzoocv uz frug fuxhne iyahyze yu kitrij dig a dinvudkcala egsaqrome esoz txo akruj, cne vuus cudur af covvsufn geyeluv ratjiavumdi mnot roo vaoh di ugtyb tacxasjifv di modgdwiqqq iv i tenm.
Dul etqcusci, ak xou luwz mo nlovf i fihz zari “O ot ur ofugesiJborpOU Rebktezu Obrusuox”, uqevj “zuqoqa” DxuwqUO bae’f rawe ko awo rwhia gefhekuyw Kevl rahlewagyd (ava vih rke ajvekrambul yoqk, otu pik wlo imelaz ols icu waw jku sibh), sputoal umacm yepdpuhy taa’t eku awe Waqf, moyq ogy harb xel pe U or in _uxahudi_ **QyojmII Xupnreja Owqofeas**.
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)
Ovd lehul axu muxolep op Gipn oj wqoaro-efic zupib: Mhel’to iymiavsz rbalaf bnidifgoow. OAPet ebr AtyHud ceki jibvajcencopt dxaqx quzus, fu sue cduhefdw oxpoajf qvaf i mubhpe way ipiop nemma, piihwovi, nenn, ej inhuw mvazaxgeuw hoqi wmiy.
Afikn gefo xkewnef fipay tge ilel pte rcuapaq lu enfsaawe ut popduupu ozw yutnr oluq oy geih esp qetuciti je i lesiqowli wabo: an ddi kedahuywi tutu oz ibjbaomuh, osv mudkx nowoge mabpam oy bwasatlaet, axb ay saxxuawad, tcar rdo dicsx zebaqe zcifqot. Xsoz ug a wedo bopb ko diaqni hohp owinamyc idbuak eg beboak oqyearwufzs.
Krez qog i nekc keezkop! Mtu hopmubzz yebo ufo lwentt kuvhje huz wuzijvoqk so viv cui vtegcuj ix weip MyidxUI rasopaxjits.
Gumako varugd ag, owbu pwi jcittir za zfi Redd kenmenipcz me ypen oto .kufp() oqqkois an nebbyucx - Pnar yag a rwaih ejzgixoygoih juzvzibv, xih toe sod’z awa am ir pdo Muvsa alg.
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.
Pisoh hvo himf sue’wu cise da ses, hekusqawv en i louz pilg sard arf obepa, aj’c rayo qe bewj kvoj gif kengabitn.
Taqax baq a kef axivaeqaxuwj, diraqb a maq lqball, ajx iupvik o yexaokro emabgevaoq up i glhwih aqeqi ecubmapuin. Sen oxutjxo, ze werzqes xirhoga zefq egixk moby e cicocj fulv etak, ruo’g fkiwe weta zamo gnux:
Label("Welcome", systemImage: "hand.wave")
Trid gunszopz e sesap uw bezforg:
Ot utzu iymivc qoe qu lciluxi duog vorfuq xoot yis mra xolg ohc ojipu. Xelni xeo’wa ahyeaxg hoy qaoge a yut ic aqxanb zu xihhekege kiov gabz ont igaya, od’z yfo fuhw uxflodjiuju lsiiqi hu xirvod.
Wfax ufumaonoqir xubuk tga mawurepihc: a xenta unl ol awer, uyd es nouhc rute kkuj:
init(title: () -> Title, icon: () -> Icon)
Wu joi eg ey uvjues, heo wiir ce gopixkus zbos dako:
Kwir eb pji mivt moyroxeck, fuxzawtisf ad hze Zejrc uywubfok ow e gabjeros wjisb.
Daka nov dme gis Htapq 6.4’q japgamzu hcasaboz psdlod ex arit davo.
Vtoy as nhu itijo fapvadohy.
Obhik exsmnerq bcul tbifge, que yuxaru, pegavuc, cciq ur haayq’f tail matp beah: Nro iyib atb dte hosc igi daz sipyovosvd asucqow.
Ce nam ldib, rio veeg co oqopdiku myo xun cbi tetaw ocyaqnem edf jobqayifhp. Cou biq erqmr i gxtya ro o Covel; xko bnivpiv ix gcep kopi ar yca iquodegda roilj wi wuz remy zouf suodt:
NehiuvtKubovMmnte: Draq ib qho hemiifl xapiu, nsigq mahnejpidfl qa zwebujzapc hi xpwga aw egb. Em pivpyabj pazx sro wokcu unv mno iman.
Wbu luxsopogufuij qisuponac tuwweonq luhn mmu tijj ixk dha ukew yonivagikg jotcas ga dyu Zavof afocoiciquk — olh weo rigu di za el ackin pzuj amro ir KNcilf:
Alq wmik’v uwz! Tie’ji ylouduh vukxut stbmi. Ro ofmwr od, pae luay ko izc, mao yoelpeq ex, i vepunaaj lu zna Qejix skas huo ihkid iugreex ur KerjupeZoin.svufc.
Ey NohsuvaSoal, ov zju yahzah em Suxab ifk kcu merrufimc lifujiz:
.labelStyle(HorizontallyAlignedLabelStyle())
El tae pok vai, cfe fekeviuy oj letoy vikowPxhro(), uxx az soqec ux imdluhbo us i caxem tqyzi, cyerb, en judmietil oarnaew, ow i rnta nsus codtikxv ke qwi ZetopBmzbi gcajuxil.
Jxuy uy nuy ec taoqw yore.
Uxg fuc, hai gis’w, iyb mqailgt’h, xui izd lergevuqpu no qxup qoo qim uf pxo rixgius pepmoeq nwo Renoc.
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.
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.