Support for NSTextAttachment
ngoleo opened this issue · 0 comments
ngoleo commented
Is your feature request related to a problem? Please describe.
It would be nice if we could support rendering an NSTextAttachment
inside an attributed string, typically used to render icons inline with a label's text.
Describe the solution you'd like
When attributedText
contains an NSTextAttachment
, render the attachment image inline with the rest of the text, similar to how UILabel
renders these.
Examples of usage:
- https://www.hackingwithswift.com/example-code/system/how-to-insert-images-into-an-attributed-string-with-nstextattachment
- https://medium.com/@nemanjavlahovic/nstextattachment-13dd7ae326e4
Technical complexity
- Rendering
NSTextAttachment
's inUILabel
is likely managed by TextKit'sNSLayoutManager
, which we're bypassing and substituting with our own CoreText drawing inNantesLabel
's implementation. Making it work with CoreText might not be practical/possible.
Describe alternatives you've considered
- Just use
UILabel
itself, but you lose out on the benefits ofNantesLabel
. :D - Explore not overriding
func drawText(in rect: CGRect)
and letUILabel
do the rendering. Not sure if we can do this and still support the current features.
Additional context
TTTAttributedLabel
itself does not supportNSTextAttachment