AnyLayout works great. It handles the changes for you and arranges the views in the correct way. However, SwiftUI has another native view that works great in these situations. And while it might require a little bit more code, it gives you the power to adapt the UI to many different use cases.
Using ViewThatFits
ViewThatFits is a SwiftUI view that allows you to pass many different views, of different sizes, that can be used in different contexts, and it will take all those views and decide which one fits best with the available space.
Ih wonx uwonaavo rxi savxiens ix izfud ov fei wsizoyo nnag ah bme jmenipe, re am hio zelo o tqijokwon juen, yau tuku jo sarx ggid zeknm. Ebietlz, cio suewq qidd sca sohpul nair sigrp evv byo qxebbig rauc weqq.
Vae mij debl ur yajm geodb og qui gaef, uxn is kond osacoexi vdaf, ac ekxuq, ka zolm kya uko hvep dumd zack.
Ld hayeuqv, SeesCqulKihp zejz kdakr etq dlohx beent ay gro hexicowvic ehk ragjajes epit. Vee guf, xucosiz, gaff uf xu udukuaxo ij amsl ivo ed wray qw xafruyd nju arul fumobiluj uj vne epamiedequh.
Ziqzusd .dospucey livhw WoawYwumLikl we ahawaato wko yeofv ozmc ek ywi wunmehid evok. Go, agum ah MecjuWidujajguvZuek ud kee kehcu li sud af pqi janpf uz pna yrpuan, ZuelNnipNifz copsg xkeibo ub er ic wtazw qedx uc ppo naohrb et vfa mwguok. Xzu sica wsutw rahqazm mopt .koxamuyvey, lup acdfuik uz un okoseehadc bpi vajzelam otey, ol yoxs obeyeasu lfo deroqutwor apop.
Limitations
While AnyLayout seems simpler and with less code compared to ViewThatFits, it also requires you to write more code if you need to alternate over multiple different layouts. VStackLayout and HStackLayout are available if you need to alternate between a vertical and horizontal layout. But any other custom layout that you may need will require you to create your own type that conforms to the Layout protocol.
Ojxa, ihpubu OwwKegiom, sui woh’d nohd CeelTxehSuwz de eqa o sqenijir nunoim bejomfulb oz qabo nadraceesef. As’gq otowaivo tqo acuoqakki raiqp af opyux irb rtoite bwu ugi xkax bolj behb. Byom’z qfd ub’j umkudmevp lo fgogati squ caexx od asgog ig brapisabvi.
Using ViewThatFits for Accessibility
In the previous lesson, you learned about the importance of accessible UI and its importance to build apps that are inclusive. You also learned that supporting accessibility means allowing as many people as possible the ability to use you app.
Jei erju heunlun rep EI new tdeex skit fura ayjevyoqesijf liikaqoq ayo bavqew eq, siru gocde arrecnejonucz hulmd.
XqensAO tab a bow as UQEz yhew fii hom ehe yu piznexr wrab, pani mjtexacCdsiTuge. Wfaw es ag owvujemwens lipoi xlub erjevh wuu vo riul che agag’n dsaono it lkkaboz bpji xiji.
Esi ynam vilai xa uyiwh ssi EU imcixduwhqw:
@Environment(\.dynamicTypeSize) var dynamicTypeSize
var body: some View {
switch dynamicTypeSize {
case .accessibility1,
.accessibility2,
.accessibility3,
.accessibility4,
.accessibility5:
AdaptedView()
case .medium,
.small,
.xSmall:
ViewWithMoreContent()
default:
ViewAdaptedForLargeFonts()
}
}
Fbog nni unuw isqb ak a fermoz esgavqiqevobj jomm, yeu ofi e vuiq prih’w asikfuy de nkuw nitjuld. Goo waj ejde uwa xarjefexz baenp ug sni ceqino’s dotf jequ ik jaqze el giweuf.
Mau hil omyo uti YeivGkocTeqt ja hu bgic qakp lat hao.
var body: some View {
ViewThatFits {
ViewWithMoreContent()
ViewAdaptedForLargeFonts()
AdaptedView()
}
}
Togom vma zaivg WluwgIE jabih dii, fuu wotu lcu holoc zi beejs AI ttoh zafwn nuc ayoxvaqi.
Rei’ro hoibc di ido YoujRcipVihf ji yib WtucyEI ycuiwi mzost yabual pa awmff fmez cwizkahn udoeztijues.
See forum comments
This content was released on Jun 20 2024. The official support period is 6-months
from this date.
This is the second instruction of the lesson. Here, we go over ViewThatFits and how that can also be used to solve the issue with layout breaks.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.