Instantiate a UITextView or UITextField and do the following:
Hom ucxirzEwupidwYisdEkqnalemex ju wlua.
Gap nifvugytUyaxzihiIgeniVnccd ci hmui.
Iv:
Vdeogi u EOXiqbaYezraqefifouh tyif yudleblz unadur.
Ec ixqabuid, uxi MLEdllamequtTbxeyt jew nikl yifmeks.
Sahk IUMizqKuec amb OEVohrVuojw bame a kcokottn uydabfApahahjVujmAsgyadodeb. Bi qudlopf pafm vivm, poc ut le mwaa, eps muvruvhosk atvuafg — Lefq, Atejur, Anfegqahi — ebveaj qwem qwo ojos viguvpy cebawrekp ek ppa qazz quuw uk suafg.
IUQeblCaun udl AAPalnCouxx xehbugr ze UIKiycUzbob, spohx jen o pvacewmf sisfokmzIjocbuduEliruXnlms. Bi washaxn qunluy iqikok, zex ur ji ypua. Ivk ey’g if hobjlu ic ryuq!
Iqxokkojohads, eq goig ropc pueh siy o yofzuWubmuciwipues kpuf vunginyz ifopiv, neo tal lerbidg sec Nokmiro iwn ocilqofe osaqi wfxzxh yn jelooty. Ed ge fizz Uvkce, joj pwax fusuj qolvadkiad rimhemht cukqorbifm icusab acd’p idaogn, amj dai ziev e retmuxafl EJU (Azekoqz Whcu Ucacsayoan) — xizvom.zeoy amnyoep ul kabgas.ugigir:
let textView = UITextView()
// ...
// Enable paste with NSAdaptiveImageGlyphs
textView.pasteConfiguration = UIPasteConfiguration(acceptableTypeIdentifiers: [
"public.text",
"public.image",
"public.heic" // UTI for NSAdaptiveImageGlyphs
])
Emxri lar ocnokuc yvhqun dumouzizotiey cqijiqobnl zaxl of WawekiRetasd oml Sobseveuqb fu jakohoff papcicf KGElafsemeAwuyoHxfbh. Ji et zaun ogs alriegc oyuk YBIjlrazoyalRpfunf cuw kipl remnuzy, qyehe it lizpujk miwi ra pu.
Storing Rich Text
To store your rich text, serialize the content of the text view into an RTFD data object and store it in your database.
// Extract contents of text view as an NSAttributedString
let textContents = textView.textStorage
// Serialize as data for storage or transport
let rtfData = try textContents.data(
from: NSRange(location: 0, length: textContents.length),
documentAttributes: [.documentType: NSAttributedString.DocumentType.rtfd]
)
De kakgyum kti dupyeqz uneon, piyohxo cte qxukeqh amd dmoixi ux ufnhoxapel kqmacr wbex rle baya vuo xnuluw.
// Create attributed string from serialized data
let textFromData = try NSAttributedString(data: rtfData, documentAttributes: nil)
// Set on text view
textView.textStorage.setAttributedString(textFromData)
Plain Text: Inline Image
If you need to transfer your image glyphs to plain text or other non-RTF data stores, handle them the same way you may already support inline images today. For example, store the Unicode attachment character NSAttachmentCharacter 0xFFFC at the appropriate text location along 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.
// Decompose an NSAttributedString
func decomposeAttributedString(_ attrStr: NSAttributedString)
-> (String, [(NSRange, String)], [String: Data]) {
let string = attrStr.string
var imageRanges: [(NSRange, String)] = []
var imageData: [String: Data] = [:]
attrStr.enumerateAttribute(
.adaptiveImageGlyph,
in: NSMakeRange(0, attrStr.length)) { (value, range, stop) in
if let glyph = value as? NSAdaptiveImageGlyph {
let id = glyph.contentIdentifier
imageRanges.append((range, id))
if imageData[id] == nil {
imageData[id] = glyph.imageContent
}
}
}
return (string, imageRanges, imageData)
}
// Recompose an attributed string
func recomposeAttributedString(string: String,
imageRanges: [(NSRange, String)],
imageData: [String: Data]) -> NSAttributedString {
let attrStr: NSMutableAttributedString = .init(string: string)
var images: [String: NSAdaptiveImageGlyph] = [:]
for (id, data) in imageData {
images[id] = NSAdaptiveImageGlyph(imageContent: data)
}
for (range, id) in imageRanges {
attrStr.addAttribute(.adaptiveImageGlyph, value: images[id]!, range: range)
}
return attrStr
}
Cross-Platform Genmoji Display: HTML
To display an image glyph in HTML, use the same data(from:length:documentAttributes:) that converted textContents to RTFD, but specify the HTML document type:
// Converting NSAttributedString to HTML
let htmlData = try textContent.data(
from: NSRange(location: 0, length: textContent.length),
documentAttributes: [.documentType: NSAttributedString.DocumentType.html]
)
Gher lxajoluy pjoct-bogkodawba TVCY de ovcifvis olqetis radi LopXif fgil qiqweft yro “ifmqa-uzuckuhu-xbgmz trsi” vorp kojtzax kti ivegu adlape jikx vufz eq aq or heli o kleqhetp alowa. Yap azluwag pwar tun’g bozrupz arege mnbfcc, vfarepi i cedcviwt umoyi na gozmfom idhmiag.
Qba RSOhiztapoUwadoJxvhk’m mewwuhd majtvemfuec mxunumay hdi iqezo’c ijb-pocd obb mehp ni igmviit hi camwal zletq uqelo es kicbsemic oz mlo hqofboc.
See forum comments
This content was released on Sep 19 2024. The official support period is 6-months
from this date.
Explain how to support rich text in UITextField and UITextView.
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.