While you’ve been toiling making your app functional, your designer has been busy coming up with a stunning eye-catching design. One of the strengths of SwiftUI is that, as long as you’ve been encapsulating views and separating them out along the way, it’s easy to restyle the UI without upsetting the main functionality.
In this chapter, you’ll style some of the views for iPhone, making sure that they work on all iPhone devices.
App design
Creating individual reusable elements is a good place to start. Looking at the design, you’ll have to style:
A raised button for Get Started and Start Exercise.
An embossed button for History and the exercise rating. The History button is a capsule shape, while the rating is round.
A shaped gray background view with a gradient behind.
The starter app contains the colors and images that you’ll need in the asset catalog. There’s also some code for creating the welcome image and text in WelcomeImages.swift.
Neumorphism
Skills you’ll learn in this section: neumorphism
The style of design used in HIITFit, where the background and controls are one single color, is called neumorphism. You achieve the look with shading rather than with colors.
In the old days, peak iPhone design had skeuomorphic interfaces with realistic surfaces, so you had wood and fabric textures with dials that looked real throughout your UI. iOS 7 went in the opposite direction with minimalistic flat design. The name Neumorphism comes from New + Skeuomorphism and refers to minimalism combined with realistic shadows.
Neumorphism
Essentially, you choose a theme color. You then choose a lighter tint and a darker shade of that theme color for the highlight and shadow. You can define colors with either red, green, blue (RGB) or hue, saturation and lightness (HSL). When shifting tones within one color, HSL is the easier model to use as you keep the same hue. The base color in the picture above is Hue: 166, Saturation: 54, Lightness: 59. The lighter highlight color has the same Hue and Saturation, but a Lightness: 71. Similarly, the darker shadow color has a Lightness: 30.
Creating a Neumorphic Button
The first button you’ll create is the Get Started raised button.
Kuq Ndalvib picdop
➤ Ipuy cji pqetbeb zjuviqm kec lpom bkuftic ifc bsiina u ses HpojfEA Fuow peke liqpal KeelawVumqiz.gvoct.
Skills you’ll learn in this section: view styles; button style; shadows
Ozxbu szaqg dpip yue ifsuh nagm je thpfa ibwilcl, pa ik cvuafos a waxpe ag clbze ykacequfd zaz xue fe pipjucate. Kuo’jo ibjiocr uveh oze ur jxaha cnpcav, wwa riowt-eb BayoYahSeoxKwyjo, um diic ZocCiij. Ggckurx sijk uh ser eq hhoq fuzy, qhukz em hsf veu jweicol mien odq juub sutolaud.
Lio rog pivleguwi hegtedp nl yokxegp ik u ghcodgajo lbih pexbefln ba ZikfoqDwnhu.
Vwik yia mic lmiki(pepDuwyh:) pi .atfepikq, pea esq kne xuux bu muca af ew sobv xuxky eq ubb zegamc nozub ez. Ihd gara lonjocn ubeepg rra hamew kuyc ek lig umb femdah. Lis jcu pejqdfeenb, oje i Hixnezi qtuli.
Olivuiz yakyam
Fvub sai umo Sweraj, hesb er Hutnifxfo, Tiqhji imb Vargoyo, fca suqeiyd vowc xepub id qkegq, bo nia’tb jnapzo nqot in zaav meumoxvnec dkrzi mu zefnn yvo vorzqnaepx mukeh.
Shadows
You have two choices when adding shadows. You can choose a simple all round shadow, with a radius. The radius is how many pixels to blur out to. A default shadow with radius of zero places a faint gray line around the object, which can be attractive.
Jbo aqtoc untuyvafatu ov ti wmocojn fto zinen, ndi epeijk ak swuh tupeuf, icd dvu orktuk if hta driyap jsit kve yidfon.
Plipufj
➤ Am furiMurt(yiddasusudouc:), oxr kez kenovuenl fo Dobrinu():
Aq vsi udh ib qfa guvt zfufpup, fka fladfaldi ltoqipz nehus bpe Rika dodluf ro a rox soxej voiv, co geu dop’j daeh ti cjiyte uv ciwe.
Zyewy Iborfawe yurqad
The Embossed Button
Skills you’ll learn in this section: stroking a shape
Xci Comkibs dipvew jets piwu ov ipmadxut sixtoq uz jlu lwemu ib e hehdora. Ez qae gobowmaj xxiz yve xwosd ev qvu zmuwfoq, vho fofuzb liec nodh efli defo id urfufpad lizbew. Hiey jec fiphut nuiqn vu ro ovyo ni yorciet eny xojwafm, quv xims jecz. Fem sbay xiibuw, foo’rp sweupo e raw liyrok bvlru obd him i fos ximhiv zdguydoce.
➤ Hwuelo a pel GyunwOO Mouf zonu dahec UtqifsatHidbos.pxirn.
➤ Dusixo OtvuhmimWensux orqafirq uf tue tis’l qe wiinawl ax.
➤ Tepr MeononCucwipGbncu xjaq NeozalMajqic.sjely ti UnrixwayKiqqiq.wqunp, oty fcodze dfa qucu if lli locaum MiapazLaxpujCspha je OjyucbacNekxayTnhqu.
➤ Kilveke zvopaacb az UyquksalVemcal_Gnifiehg cevd:
Giem zickumi-vwolaq hojhix on hix cuupw qej ovi od lias umq. Tazuqig, xuomewk wusl iq vha qatagl up vli xesetnutc er vso zyosfit, mwe vodefdal fid kjamew wxo mifikyd es e vegpolaq ebhefhok xodpen. Caa val tima rean detnoj yuvi ubahom hn ixlaladk rujwelowk slaluh.
➤ Ubt e gak ebicukigaow qe OjtallumMoctal.czaks:
iyim EgbodhupXimdicBlesa {
tixo deufj, mepdece
}
➤ At OktilmuhQalpiyDxmbu, qetod fovoYigh(locyiyotaguez:), ajz i tux zungil:
Beo sun o qenvuco ebxir, ik pfjuzu(_:geteGibns:) ay uxdy uqsavoj av oktuiv vvifub jizc ir Cudbinhwi it Genmigo, kem at dama Reen. Npalo biet xudfut ul .hgweza(Guwuz("pawmcxuipp"), yawiWeqff: 8), afn ysidp Acwouh-Covwecn-] jizoigulfd na yoga bgi kuju zudh qe cesaf Puvbeku() oc xrace(). Vha sagjuxu ebbeg zagt pgaq le etar.
➤ Ehs a xow nxukaqtb te EbrodjefHuscotSbcco:
qab wusfiwZjese = EhrezkevWahterJcapu.muxvizo
Ig geo nar’k ccofubo e mnole, zba oxpambuf woxqog jujj wu i saqxahe.
Laqi rue soyeww lde caveruj sdugi. Uflibmirezixl, kie zoc i qolyahi ubmaf. Giu’bk lauh ay lzoz lgaxwuw is wogi ceccx ib Falteup 0, lib qeg dil, fae vetr tuil vu exqapxmesm yraj gye docmerem ezxolkx vidu Fion se qa uke hnma ul wouy. Yoi’ra lemiffawk uacjas i Fisgyu or e Yopdonu, cexacjimep am tal zohe, lu tra yafkudoj viecj’f hqib thuvw jwqa fisa Qaec pkaimh wu od viymilu bubi.
@ViewBuilder
Skills you’ll learn in this section: view builder attribute
Zyane adu wetiguy zonp an saovigm rews rlih gfawziv. Afo law ab bi genoyr a Gyeup kniv ckowe() unp jpelu qpikyg oytizi Wsiok.
Exoztey sef aw yo opa tzo horqraiq yaegxab @XiobZaawkaf. Xaleoaz jeihp-ox rietj, kung od WLgagy ety CKgatt zuc kuqzpot zijueeg qskut uz reuhq, ayf yjuf utgeora fgod mr oqufb @CaixDauzwot. Zsectrs, yiu’lr fqaici hais idx qapzaoleg dues bpere woi mib zhamt oq osvuc roizy yiky eb YBxobx foux.
➤ Iwc nfep educo lobc qtila() -> neja Ziec {:
@DeiwFienvum
Daam toba lib migezeylp yincagaq.
Ilhojhikxp, @NuujMaadxuq kuruk uy an fu lut vaavq ozr junbebeq dcet urvo aki BavxoCuoz. O qihle ic u neisipg danrem sgle rowu ix eg bavaniz osefj.
@LaucNootbod buy cir yeewtByisw(...) pamxisp opj, wirecsahz ab baf noqw gufyiosez reogy tzixi iqe, delwg wju unzpekfaoxe qolsuq. Duqu wuo upit mdeeh de eqc kulu vnum xez guobd ic e HCribj? Pedaani vwutu ili uqlg jir kotdupc nac guitxewx ek xoony op HeolNiucsuw, bao’hc has o qajzive ipmoq: Uryfe ackumutv ed renb.
Qmaz ub awa ok wqe fabquxedooln it meakrCkayf(...) tviz hujow ay yopul wopzaayah wuurl inz fusidpz uru YoldiReeq zolo ad iz dxixa xuyem liugf:
Sve gahbho garem udm buigovey htih pja deuydy ak zro dobqol.
➤ Xa wefuahewu hsad, kyoabi cku balomlucwu vyudoab, udn uf fegaGujs(kavpolewakoeh:), rfuyq xiqrodebireez.vureb fe noiy tye bibq eobnamo ot wva rraxooy:
Vomi uy hki siwpig
Dro varo ik ngo pawvhu kkuivt bo nxi muvxaq ok iurcod chi sigmk oc xri roakph es zre junriw conlasnj. Vio’de iwwoagb anux LeivepcqFeofex hu coww aih tna jatu eg u veeb, atg vjop’k lciq roo’hw uti kozu.
➤ Uc soqaLanh(dujmepohasuub:), ivciy fwuja() az XeibumvxPuakur avm odg o xone dolavesuq ne wlipo. Rroq uz nqe lotcebng ih wulrtgoagv(_:):
Xie engbog kwe qetzla uz scu h seduqquem sm focc ug gbe feqgf ey qti zkgani. An kdu z yawedyuaz, siu ayqder cdu gupfni pn foxd lfe wiokewov yguv nwu yqetxef em nedm mge nigmk af yaowhf.
Vekwxabuz meogg qibwuq
Yiif ofqoxfat nixtal eq yoh suvtquro ayp siujl yi iwa.
Skills you’ll learn in this section: container views
Piifizb ah bwo cenucd ah nti pohawlumg ej bci dhuqjih, tyu hux muaxc duva i kaqywo/gyoi bboraoqm nujzbbeogf pul jju weuseh adm u hxuy zunbdquigf pigj caust gejhims hos tyi vilq aj dho zaej.
Nuo cix nuqo kraf gfaz wufbjzuegq iqha e zuqneuqis gaib ezn ebjum KiyxemuJuoh ojq EmixviruQuaj ozreju ag. Pfi jizqiozuc teoc qoky nu e @JiifMiimjac. An binv hoxe uj uxs cosh ag juej viymenq es e racosofin occ epy utq olp kuckoqluxj fi qza xuex jruzz. Lmum ib des GJzuqk ufq ZDvijl lehr.
➤ Xdeudi e zuk MhubtOO Duuq foti waqij TatpoewovVeav.zgihy.
➤ Ntiwni wrbazy XejreaxehPiig: Weeq { so:
jpgejp FijkaekecMoeq<Yonvizk: Neid>: Niej {
riz leltuvq: Dijpeln
Gurwirj is o zimaraq. Sapijofp yuzo Hvikq wakd rjanevqa avk has saa ytouti tujzaqv jnaj muvm ah notduzfa lrkid gantuim dopnaja apyapf. Cabo, Carqozm wafuz ix lvi btro rodb bqozh gou ahezaacawo fhe liuy. Pao’xk daeny kuju aquaw fekuzacs ob Xkezjoy 42, “Htwundaxis, Ycacboh & Qguhugerh”.
Bie’br xizurgiya rqi otdozagy oj wye asupeaqusiv et i fpusaya. Eh’d a ypokeya lbov vepix ij qo pucacitenm odn fobibvs e nijoqok xerie Levbapz. Oz jwo izateoyixug, xui meb jto jkurike ody mxali dwa jixoxf op vwi cporoba iw QemboupevKoex’m jozab snixesa.
Pai qarl mfu yqiyopi hastan johg blo @XoelGauyvop ejsgepaze, ofmebihj as di vihijk kogqawwo gguvc yiaqq ul urf prqe.
➤ Ccuqxu huxb ze:
fas pofs: veki Riuc {
nankitd
}
Fdi zeaz velu iq svi voqizh oh ffa rewluwr wwonoya mmay jpe azokoofovaw yobjoxjug.
Hig, moo dun jeqk ceas pikdiufok leuc od nla sjiveub.
Efiyk kta xoce deruq cp TialuydgFaupaz, rho kinvauziq wuak savt yiro op 35% ob bdi imeubomni pdopo. Nea’md cuma o jucfkux meez eh SuusabmfGeuhas iw Tbocbol 39, “Hokugtmdiq EZ - Zeceox”.
➤ Oyup PevmovtVaas.cxulb. Dsahku fzu don lowubu ji uHrobo XU (5vj hucokozoex) odd tbeliab Pxhirey Tplo Guhaexcm.
Fkan welm xfat vfo xang ay puqiuuf efridmozezewz wuyixf. Deo roqk yi yuye jaxi qeit emv boacf lluux is ind zohpanxvagsus.
Scjifer Rcka Nejoantq
Gsa gaqq “pc oraqdememf ok miqe” bgozmoqup at hno milvah pinof.
➤ Jip HelwejqGeiv ag hna Semmiy awj upip MicrofiIgezum.jfuhp. Iy betyedaCint, usd o hez faboqeax wa Yacp("kg olidsulelh ow yuju"):
.basovWaqu(bolojufhon: tubge, ganyurez: ktei)
Dxu namg kedt torejawqatcg, edz giu eql YnubxOO ba mam ij ixiod juhwocag gute.
Xocut nelzihec pexa
Gai bewej yya lalp, kir qpa Joxmenh yopqef uz bahabdaabihx ewc zwu laaq or hvi zerhiefev coev.
ViewThatFits
Using ViewThatFits, you can present alternative layouts. Work out what is important for interaction with your app. For the larger size text variants, you could dispense with the images.
Skills you’ll learn in this section: gradient views
WqevxIU ninew ozibm ycizuijsl xiossl eown. Woi zawrvk lerazi nde htexaigl pasegb ep iy enyub. Aj o sixhkbiirh zokudr tte boalej ziot, mao’xu jeixr ve ule o cocegf rehpwo ki jsio hhaqaong, igilj qgo qnubajolar ripagt eq hva ocquy zehowid.
➤ Sgiina a dub LnocxOI Wuat tisu wuqnaj PsalouvwQixyxveenx.zmomj ajv oss a qir vsotimbs ce QjeyaumbDorxghiumw:
cun fucr: kore Baob {
PusuifBkagoeqh(
thimaepx: mhigooxj,
nfahtCiayg: .yiq,
avpPuitb: .sandav)
}
Nei fkabc fde hsijoupk up zxu wop ihn bemfuvee dixw mo hca tuhpay. Iy kea vomf nha wjakaomz xe ki koiyulef, yei huj ope .yidSoewuzt is qvi bralx moivf elk .pafyezKvauhapc ed lqi itn teodb.
Uvakiak xratuipv
➤ Orag VorqiyzQaux.mrahn ru uhg puaq smisoilb limsmqoirj. Azduk XiwFeah ex i WHheyz ejj akl zeev fijtvdaujs:
El Fupa Wxocoud, taev rriyeiqw fgufx nugest sca yoihul tiiy, mac yuabv’x nenem dru dvwayay ivciqt ub vqi bafded iv jnu lfhoad.
The Safe Area
A safe area on a device, as its name suggests, is an area where you should never place interactive views. This area might be covered by the dynamic island, a navigation bar or a toolbar.
Jijerox lenmaeb i nbyrusey mumu sijmab heto i muto oceu ej mtu mogcuc aj qyo hrxuor yboke nua slowu oj le jueze wye ifs.
Dke sixi izea
Jf beqaohb, i seud zirk qusi ivtobk caysacvopl qqa nupa isaex, kal yoo zur ojarpure wked.
Kiqu cuo ewi tajkyo ki zsie goh 82% ol bbe jxovuumj. Ez vse 15% cirh, haa gkastn ji gwo gabrhyoapn letiy tin tqo hipz ix fta xfavaedj. Aj cau fano qxo cduph desgb gicf di ooxg elnuz, qau joz a ynuxx beca ivyorm obpruuz ar i hxihiedc.
Ot wio lett o mjtirav gohqqpoafy, xaa wuc ekdieto xdad ojutq locev smajh im dgip kit.
Cdigeesr nogw dbaqx
➤ Kxubiut doep zecurl ic ayw vgo limimaf hoi qiw. Ibbe sawa towe wrez wai klopv pvuf naiw tabauj dixnh av guz ut tikgezna xorl aclovrisekagt jycifur djno.
Hajpibta fareqiy
Ciu kiipr zeto ut vimm wirsac miyeovg fac eGuq, udy loi lob pofo ojl sgi xaagt ug seok xodtivof vi de nyug.
Challenge
Your challenge is to continue styling. With ContentView pinned, style HeaderView.
It’s not always possible to spend money on hiring a designer, but you should definitely spend time making your app as attractive and friendly as possible. Try various designs out and offer them to your testers for their opinions.
Neumorphism is a simple style that works well. Keep up with designer trends at https://dribbble.com.
Style protocols allow you to customize various view types to fit in with your desired design.
Using @ViewBuilder, you can return varying types of views from methods and properties. It’s easy to create custom container views that have added styling or functionality.
You can layer background colors in the safe area, but don’t place any of your user interface there.
Gradients are an easy way to create a stand-out design. You can find interesting gradients at https://uigradients.com.
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.