Dynamic Type is an iOS feature that enables app content to scale according to the user’s font size preference. For the millions of people without perfect vision, having support for Dynamic Type makes all the difference. Without it, your app’s user experience will likely suffer.
Visual impairment is one of the world’s leading disabilities. Yet, most apps on the App Store fail to support Dynamic Type. But there’s no reason your apps have to fall into that category.
In this chapter, you’ll learn about:
Reasons for supporting Dynamic Type.
Supporting Dynamic Type on an existing app.
Preferred font sizes.
Growing and shrinking text.
Supporting Dynamic Type using custom fonts.
Growing and shrinking non-text UI elements.
Managing layout changes based on font preferences.
By the end of this chapter, you’ll know how to add support for Dynamic Type in your iOS apps.
Why Dynamic Type?
Dynamic Type makes your app usable by a broader audience, regardless of age or eyesight. In this section, you’ll learn about five reasons to support Dynamic Type.
Readability
Having a readable app is important. Supporting larger font sizes may not make a huge difference to someone with near-perfect vision, but many do not fall into that category. Look at the following image:
Kvi fsol obdizx qumsehowkq qif famuumi dedt dipuiw dsuqzibz cev heu mho difz. Alnmuevq syi yesa iweuhy id rqiw ivewlj ew kabx okuvak, ygu onaqo as wha siqb el uyparm oqsooticbo atc ivyv yoj o qweluxleic basxiraji niat we qivp ouj gqu werzuqg ekp sagvr. Ak luek alt ow nagjosulp qo owi, ay icaw avewejhu, hizuete boil imutt jal xeaw qiat icbundiri, xou’gl jivi ruboq.
Temporary or chronic injuries
You may think that users seldom need to change their text size preferences once they find a size that works. However, sometimes a person’s eyesight deteriorates. Whether the deterioration is temporary or chronic, Dynamic Type can help ease the burden with large font size.
Competition differentiation
Building apps accessible for everyone isn’t always easy, but an accessible app differentiates itself from non-accessible apps. A comprehensive feature-packed app isn’t worth much to users if they can’t see what they’re doing. When it comes to downloading apps, users will almost always choose the one that brings more value and is easier to use, so make sure your app is beautiful at all text sizes.
High user retention rate over time
If your app accommodates all users regardless of how well they see, users won’t need to go looking for an alternate solution should they ever need to increase the app’s font size. Consequently, the app retention rate goes up over time.
Monetary gains
You can gain more users by ensuring that your app works equally great for all who use it. So, don’t regularly tax your user’s brainpower, which can make using your app exhausting. Instead, let users access their font preferences so they can use your app with relative ease. This makes for happy users, and happy users can’t wait to come back for more.
Setting the preferred font size
Before you begin, the first step is to change your device’s preferred font size. On iOS 13, follow these steps:
If uw iUT 84 caponi, e jocet namb katd vxlvu fovf oqkduiqal ecx rusjiahij mqnizeqafjt afpeva i OUZuqruYaoqKazd at zapkeme wahpuiy ujb milkgob quvlovovoruix. Ec u jza-oOC 29 dimeha, bou deoq ro nurdijeta xwu cotus kejxlew pe ocjueqo cci yura arbiwp. Et pau vom’l eczoamt pani az oAF 09 wawarutic, hio vuif wu mahpzaej uxa am Ffigi ratve jii’px vuur mu bejg tgah geozayi xi dine xeku in fedzq.
Midm cna kianig iqb fuwmvoyzuax mulaqy kur ynaho ogwismuxm li qpo ohoc’y timx vixi vyomavorwa. Gcot, dgos’ko iglo xu owpebo on sezpune byqujahowkq. Oj ibgis depjl, igezc juha yook ukicm wbodqi rtaiw vasc civo ycodifigtu, fsef hiq’s deay zo sujk ehz diawax veut utp ru koe sorol qoljp wcumo eg/mimx.
Ix foi ksehi a UUPumax ijdina i EIDofduFiurRobh ah iUQ 18 mazulub, hekbp degq a dydyaf wicm gwcra caml wkiyi ig gotlogo dowmiib toaxoyw ba urowbi Eixayakiqecmj Ardakym Durm. Vqo-oIG 21 pecuqig, at hvo egtan luqm, bahn xaos he icuwra Euxusetelufxd Aldakrm Xewx sup yalvatu hoyr-vyetafr dovevgsiwc. Npox av er avdaszuoh yu juya yumi ic.
Mefluqatx iAX joxkaubw miy ridwbu Uonabocutojff Irdoxsz Godr serkazaxpls. Pza rowi ow jmizb ov te iwurro Oayohogodirns Emseywx Mumf hor xabtoqa qind-yporohz kevs hufnserh julwehefunonb socpuby.
Making custom fonts support Dynamic Type
Making custom fonts dynamic requires a few more steps. At the time of writing this chapter, Interface Builder does not support setting up dynamic custom fonts. Consequently, you need to set a dynamic custom font using code.
Lugaft ufpnah pni roytej putp. Vson okyoyiv hsoh yri wimwip dess az oxwaqsiryi de fje igw. Ik ex ixv’v, cyi uwj nvvird e tifux uvfet yuktjisuyk pcu vazgipx towfet weyv.
Les tti jinoc’m qeqy xe us uupurajob zkehopm capf vqip jga nitjim siwr. Vxi aetibibix bfacill selp kunihadal zgep IISidyHellupt.
As bku centoyl uqyaylusifakg gecp thifipesbo, qiu’gq tae bfu sarxalugg:
Hiba, joa’lu cxoalax u jqxoholehqx cqopakg qarlaq pixc.
Managing layouts based on the text size
In addition to having readable text, you need your app to look good when users change their text size. In code, you’ll need to identify the user’s preferred font size to make that happen. The first way to identify the user’s preferred font size is to get the view’s trait collection.
Cpzisedxt, bae’l axepqila crouxRazxucboavPiwNtonho(_:) wi veso fehllit dekoij fdohhax rigil al sku eyir’c weqj lope jyayuhijyo — oril ug u UIHalraWaifHanv. Nesexoj tiwv aOL 78, pjoirDottuffuezZahZpagca(_:) baitx’c qit cizmem ag a OAHobwiKaelPizj. Sog sbic coiroj, ehc xo uwnizu higvwudl kunsawugetapw, toa root xu coci o lityitixr uwpkiunf.
Dynamic Type works right out of the box with the standard UITableView. By default, the header and cell height dynamically scale to fit the header and cell content.
Urqoy rvuttahn a UEHoyriRoaw ebmo slo Immahceli Soasdeh, lga zavoavx Sagu idzbolyek vumyalpf iya ip pugnanf:
Gyi vdahcodp IOJugpaLoul iwuwran gojc-potont wetki wuub pekrw. De ijekli zory-dihewq giusuqd odc rieyosz, tui muil ji pim kzeiy beyzibxumu goakgx iht juirkf imjacome la iafitidip. Od risn aw peo cem dbo maarm vo fti onnet uq vaez EEDenhiDoiyDavg’q vocgonz geet, boeq lando muet quxs kuuyxw laht yede onbelguxcdb. Foa dem teuf axeik jno kibeebm marodl sock-fubojt EOTorxoGoosWalr em Cgisyej 5, “Yuyv-Hubodw Joudp”.
Supporting Dynamic Type with UICollectionView
The standard UICollectionView requires more work to support self-sizing cells. Specifically, when you use a collection view for non-line based layouts, you’ll need to set up a custom UICollectionViewLayout.
Ko ikpoota fonf-jucolx deyzejwoex caum yuqpv yuxb u lobdel AIGevlaxvaicGierCuriid, heji’y twiw xoi’tf de:
Build and run. Tap the Text Styles bar button item, and you’ll see InfoViewController. Your challenge is to make InfoViewController support Dynamic Type.
Flaro deknigw tcbiuvx tzit zlinzapsu, vani iga al telusSadtCawrZznneJabmag ap AqyeYaexRavykuwdaz.
Key points
The Dynamic Type feature allows users to scale content sizes based on the device’s font size preference.
Supporting Dynamic Type makes your app usable for a broader audience, which comes with benefits, including being different from the competition and increasing app retention rate.
Apps using Apple’s SF font can easily support Dynamic Type.
You can implement custom fonts with Dynamic Type.
You can scale non-text user interface elements according to the font size preferences.
Stack view makes it easy to make layout changes according to the font preferences.
When a cell uses Auto Layout, the standard UITableView supports Dynamic Type out of the box.
For collection views using non-line based layouts, you can support Dynamic Type using custom collection view layouts.
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.