Last active
April 7, 2017 10:34
-
-
Save funkydevil/8cc0f974ec1c9ec360456a7edfcca828 to your computer and use it in GitHub Desktop.
Copy attributed string to pasteboard
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
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; | |
NSDictionary *stringAttributes = @{ | |
NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:13], | |
NSForegroundColorAttributeName: [UIColor colorWithHexString:@"4C4C4C"] | |
}; | |
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:@"Text" | |
attributes:stringAttributes]; | |
NSData *rtfData = [attributedString dataFromRange:NSMakeRange(0, attributedString.length) | |
documentAttributes:@{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType} | |
error:nil]; | |
[pasteboard setData:rtfData forPasteboardType:(NSString *) kUTTypeRTF]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment