Created
October 4, 2013 02:04
-
-
Save Daij-Djan/6819943 to your computer and use it in GitHub Desktop.
This is for DTCoreText.
I fiddled some time with this.. I wanted to get a custom view (not html based) into a label. I found I had forgotten setting the CTRunDelegate :/ So it wasn't resized ok. now it works ;)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@implementation NSAttributedString (DTTextAttachment) | |
+ (instancetype)attributedStringWithTextAttachment:(DTTextAttachment*)attachment { | |
NSMutableDictionary *mAttributes = [NSMutableDictionary dictionary]; | |
[mAttributes setObject:attachment forKey:NSAttachmentAttributeName]; | |
#if DTCORETEXT_SUPPORT_NS_ATTRIBUTES && TARGET_OS_IPHONE | |
// need run delegate for sizing | |
CTRunDelegateRef embeddedObjectRunDelegate = createEmbeddedObjectRunDelegate(attachment); | |
[mAttributes setObject:CFBridgingRelease(embeddedObjectRunDelegate) forKey:(id)kCTRunDelegateAttributeName]; | |
#endif | |
NSString *s = [NSString stringWithCharacters:(unichar*)NSAttachmentCharacter length:1]; | |
return [[NSAttributedString alloc] initWithString:s attributes:mAttributes]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment