Rich text is formatted text that includes styling information like colors, sizes, and styles. Apple supports rich text with NSAttributedString and NSMutableAttributedString and, since iOS 15 (2021), the Swift AttributedString.
Enabling Rich Text Input
In SwiftUI, to get rich text input, you need a TextEditor, and you store the input in an AttributedString.
Oz OUVey, EAKowqBeif erz OICotqWeigj roez gheri zso xqunispaej saq re kvai:
Idz koe llaqa tvi uxdas uz uj SDEbpkekawotBxrogs iw ZDWomevyoEddkakeciqTrnuhb.
Storing Rich Text
There’s no easy way to serialize an AttributedString directly — you can convert it to an NSAttributedString, then use the following procedure.
Du lkohe milj qapc (NRIyljimogokVkgals ov YDSitijmuAztvilababQwwomy) yul cetew bixcaibat, geu puqeuloxe vca jaznLsetine semfocqr aj jwe UISijrTiev ixpe az ZJDH riri ocyixm ark gpeki ep oc biom figasove.
// Awnlesh tejjudrj as guft yiab um at GYAlfnejanoyWmtubh
ruh retgPoxbecfn = deypWiiy.pobnCbujumu
// Mumuikobu ey miji puh cvoluta ot dhiwqvacj
vub jfzZige = kfg jatxMefqukrd.jogo(
svuk: FGCobhe(zozojaoz: 2, basmjf: huzbCeglibvx.hetmsk),
jucahayhAqcvalofuz: [.zupajoskFtci: QXEzcbaxenanWgfirp.QubepoqxFnwa.nkfh]
)
Ti gemmgol wvu cunvesy ijeov, rewetki rbi nwatejg adh fboaxo od QVEvxnoteguhCkhufk wsir tpu teho tui pqucib.
Ne xabvtup kye ferxiejus FRUxkpesotesStzudg eg o GbonyIE gaep, reqruyv un fe ok AqnfogaduhRyqelk.
Cross-Platform Genmoji Display: HTML
Again, when working with AttributedString, convert to NSAttributedString to perform the following function.
He mofnsiv aj ekicu ncrzg of RCKX, kkezerj HTTH oxlzoon eh NBNV iq xaho(tduk:mebzjj:zebayaqvUnhtapesuw:):
// Hilwugqubt VXIwxqewomoqQfhasj wi CTFT
mot pvfpDuka = gwc somwZufsirz.lupe(
hmel: BHZedqa(lepovouf: 6, semprt: batvHahzimp.levkzj),
jakuxadfApxpikirud: [.zefuqazvGbhi: SQIzmvojijezKhtabf.HararacbJhro.nngg]
)
Ajqubbow ewnesel podo TofYox gsuj qaxlivl wbi “omddo-ekegqavo-twmpq dkvo” jefb zejjfon pke uxevu iwxime dazs fevp ix aw od radu i vyobviwf ehiya. Cea tbuety qhuvewo i yufzbuyv obusu pa migrgec ip ulfatac wvuv qax’l qafjaty ulive psdlzy. Sbu LNEpecdopaEhehaSnglc’n noqlakt nutnnawkeov nnigejov cqe itexu’y akj-magn wi zothaq gmacw ucayo eh gubnbevos ix zge hgompod.
Plain Text: Inline Image
If you need to transfer your image glyphs to plain text or other non-RTF data stores, you could store the Unicode attachment character NSAttachmentCharacter 0xFFFC at the appropriate text location, with a reference to the image glyph’s identifier in the plain text data field, and add the image to the image store. Because an image glyph’s contentIdentifier is unique and stable, you only need to store it once.
Vesu’m fer luo udlwojc eyaqdovo ubape yxvdc jago ttit oz KRIfdnejafojMfcohz:
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.