Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: NSTextAttachment #492

Closed
ghazel opened this issue Jan 29, 2015 · 23 comments
Closed

feature request: NSTextAttachment #492

ghazel opened this issue Jan 29, 2015 · 23 comments

Comments

@ghazel
Copy link

ghazel commented Jan 29, 2015

As mentioned in #447, TTTAttributedLabel does not support NSTextAttachment. This was surprising, and undesirable.

This is a feature request for NSTextAttachment support.

@bteitelb
Copy link

+1

2 similar comments
@sebleon
Copy link

sebleon commented Jan 29, 2015

+1

@blitzvb
Copy link

blitzvb commented Jan 29, 2015

+1

@getaaron
Copy link
Contributor

I've been thinking about moving all the drawing responsibility to UILabel, which would accomplish this. We'd have to drop support for pre-iOS 6, maybe pre-7 though.

@ghazel
Copy link
Author

ghazel commented Jan 29, 2015

FWIW, I only support >= 7 anyway.

@Igor-Palaguta
Copy link

+1

@Igor-Palaguta
Copy link

Does anybody know good workaround, how images can be embedded to uilabel?

@getaaron
Copy link
Contributor

getaaron commented Feb 2, 2015

If anyone wants to collaborate, the drawing-with-uilabel branch of my TTTAttributedLabel fork contains a rough, incomplete implementation of TTTAttributedLabel, dropping pre-iOS 7 support.

So far:

  • It compiles
  • The test app behaves mostly (but not entirely) the same
  • I had to comment out most of the tests to get it to compile
  • Some of the features being tested have been removed
  • Some stuff has been deleted, other has been commented out
  • All of the drawing code has been removed (so it draws identically to UILabel now)

I haven't had time to test it beyond this initial gutting, but I think you should now be able to embed text attachments like so:

NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:@"aaron-brager-avatar.png"];

NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];

NSMutableAttributedString *myString= [[NSMutableAttributedString alloc] initWithString:@"Aaron Brager"];
[myString appendAttributedString:attachmentString];

myLabel.attributedText = myString;

@jhersh - Is this an approach you'd be interested in collaborating on? If so, since it's far from production-ready, would you prefer to work on a branch / track issues here, or should I continue on my fork? I want to avoid stepping on any toes.

@jhersh
Copy link
Contributor

jhersh commented Feb 2, 2015

Very exciting @getaaron!

dropping pre-iOS 7 support

That is unfortunate; iOS 4.3 support has long been a hallmark feature of TTTAttributedLabel. I'm not sure how we would measure deployments of the label on older systems, but I imagine it is still fairly popular. It'd be a real shame to lose this even though it'd also mean simpler drawing and much less code. Still, I imagine it's only a matter of time until one reason or another leads us to drop older systems.

All of the drawing code has been removed (so it draws identically to UILabel now)

This also means that support for highlightedShadowOffset/highlightedShadowRadius et. al. have been removed, right? What of verticalAlignment and textInsets and any other features derived from the label's custom drawing? Are the NSAttributedString character attributes adequate replacements for all of these?

This sounds like a fairly major change. We'll want to try for feature parity to the best extent we can, even if there are breaking syntax/property changes.

@getaaron
Copy link
Contributor

getaaron commented Feb 2, 2015

@jhersh As you suspected, those features are all currently broken. Some of them can be trivially reimplemented, although I'm not sure they all need to be.

For those you mentioned:

  • textInsets can now be trivially configured with NSParagraphStyle.
  • verticalAlignment may no longer be necessary now that auto-layout and sizing work as they do on UILabel.
  • I can't think of an easy alternative to highlightedShadowOffset and highlightedShadowRadius, but there may be similar text attributes which I'm missing. Alternatively, we could draw our own backgrounds and add them as subviews of the main view, but that's obviously a last resort.

@Igor-Palaguta
Copy link

My app uses >=iOS7, so easily switched to native UITextView. It supports links and images - all I need

@ocrickard
Copy link

It is possible to implement this using the current CoreText engine and not fork the implementation, right? We would scan the incoming text with NSTextAttachmentAttributeName and embed a CTRunDelegateRef on the string for these regions that would allow us to leave space inline in the text. In the drawing pass you get the attachment cell and request it draw within the region left.

@jhersh
Copy link
Contributor

jhersh commented Mar 13, 2015

@ocrickard That does sound promising! I would welcome a pull request with those changes.

@ekrivopaltsev
Copy link

Folks, if NSTextAttachment with image supported in version 2.0.0 ?

@getaaron
Copy link
Contributor

NSTextAttachment is still unsupported. I would happily review a PR adding it back in. Otherwise, I'll keep it on hold for a future version of TTTAttributedLabel.

@hytzxd
Copy link

hytzxd commented Apr 11, 2016

+1

@holyen
Copy link

holyen commented Jul 12, 2016

+1

4 similar comments
@YuriyTrach
Copy link

+1

@iShawnWang
Copy link

+1

@xilin
Copy link

xilin commented Oct 19, 2016

+1

@oded-regev
Copy link

+1

@shafqat-muneer
Copy link

Is NSTextAttachment now supported in TTTAttributedLabel or still not?

@lovisty
Copy link

lovisty commented Jan 20, 2018

NSTextAttachment is still unsupported, you can choose YYtext.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests