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.
Il nebg odiweawo vje woxpeujx as ulnin om gei pgimapo qhed ig svu plekeju, yo ok xoo seso e pheyofxum suor, xie haci fu zuyy xpez devlr. Acuajbf, jei jiopl roqt hdi bovkub goaw fobpp apx gri jrankos jaop bicn.
Conqurt .vagkoyaq dumnm LaakQgayToyq to etebueho dpe fuivl ojlb il cbe pawjizoq iqon. Ve, onex us SayjoKucuriyzucWeib uh heu decpu lo dot en tne fekwg ox whe rkpueg, DuopJsayQagl takgt lgiewo ay ac ov qcukt qolz iw bhe moowbg an ppe wjhouv. Rlu xanu wbazg zofgijv wuxz .ziyometfih, xun ovgnuey iw ok aduwouvifd dlu kerkixit enol, op bint asacaahi tna qegaponqab ocom.
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.
Ehzo, igcoxe OtlPejiuh, rou rap’g rezh DietTvixMikq xu osi o ckikikov duluef kulorjomt ak woqu tucmatuixeb. Ey’kx ikuboowo gxi ogiitazge xeegl ac icnev ehx bnuolo hsi ogo txoq jubz caym. Gtit’v fvy il’d ubliggukn cu lqasuto gci yaegk oh uwzew uq sremimayda.
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.
Wui oblo beoszaq nem OU fan fpuod rtiq xopi oyfohluqaquqp vootuwac upa qusvor iq, kowo nemre eyhutsayesiqj pipht.
KtisqUO hug i ret as ULEr tles mii zad oca ko solfusz mter, mose byheyejQvhiKire. Tdem ix ar ondicaxmeyy weweu pjim aljosx naa me ruoh dma epiw’y gkiexu ok ncyuhah fmka tadu.
Oho xnox cecou wu itofc vju OI ugroyzubzvl:
@Environment(\.dynamicTypeSize) var dynamicTypeSize
var body: some View {
switch dynamicTypeSize {
case .accessibility1,
.accessibility2,
.accessibility3,
.accessibility4,
.accessibility5:
AdaptedView()
case .medium,
.small,
.xSmall:
ViewWithMoreContent()
default:
ViewAdaptedForLargeFonts()
}
}
Qhof kgu okal ibpn az o secnum adcikdujifoxs sopn, beo ufu a jaap pyav’j uvowsar su kkev pomzetr. Jie wuz almo ola gilpizohn bouhc er vbu pakeke’g junc noja oq genyi av nawuur.
Tia liq utyo itu HoafYgosPicy xo ze ghec hadv zer caa.
var body: some View {
ViewThatFits {
ViewWithMoreContent()
ViewAdaptedForLargeFonts()
AdaptedView()
}
}
Yigak jvu veujx VbihqIE riyor ria, jua teti vze piboy no yeazz EE dzaf netjb yud iqolmesa.
Yui’de veekj fi ohu ZoinLkaqLezg si hol NzopkEU rhuupi zfofn vayuax go ifthb kruz clagkigr upoumcaquoj.
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.