Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have found that when I (as a user of the application) copy rich text from a UITextView into the pasteboard, the pasteboard contains two types:</p> <pre><code>"public.text", "Apple Web Archive pasteboard type </code></pre> <p>Based on that, I created a convenient category on UIPasteboard.<br> (With heavy use of code from <a href="https://stackoverflow.com/a/6566850/272342">this answer</a>). </p> <p>It works, but:<br> <strong>The conversion to html format means I will lose custom attributes. Any clean solution will be gladly accepted.</strong></p> <p>File UIPasteboard+AttributedString.h: </p> <pre><code>@interface UIPasteboard (AttributedString) - (void) setAttributedString:(NSAttributedString *)attributedString; @end </code></pre> <p>File UIPasteboard+AttributedString.m: </p> <pre><code>#import &lt;MobileCoreServices/UTCoreTypes.h&gt; #import "UIPasteboard+AttributedString.h" @implementation UIPasteboard (AttributedString) - (void) setAttributedString:(NSAttributedString *)attributedString { NSString *htmlString = [attributedString htmlString]; // This uses DTCoreText category NSAttributedString+HTML - https://github.com/Cocoanetics/DTCoreText NSDictionary *resourceDictionary = @{ @"WebResourceData" : [htmlString dataUsingEncoding:NSUTF8StringEncoding], @"WebResourceFrameName": @"", @"WebResourceMIMEType" : @"text/html", @"WebResourceTextEncodingName" : @"UTF-8", @"WebResourceURL" : @"about:blank" }; NSDictionary *htmlItem = @{ (NSString *)kUTTypeText : [attributedString string], @"Apple Web Archive pasteboard type" : @{ @"WebMainResource" : resourceDictionary } }; [self setItems:@[ htmlItem ]]; } @end </code></pre> <p>Only implemented setter. If you want to write the getter, and/or put it on GitHub, be my guest :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload