Skip to content

Instantly share code, notes, and snippets.

@funkydevil
Last active April 7, 2017 10:34
Show Gist options
  • Save funkydevil/8cc0f974ec1c9ec360456a7edfcca828 to your computer and use it in GitHub Desktop.
Save funkydevil/8cc0f974ec1c9ec360456a7edfcca828 to your computer and use it in GitHub Desktop.
Copy attributed string to pasteboard
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