ich gefunden habe, dass, wenn ich (als Benutzer der Anwendung) Rich-Text aus einem UITextView in die Zwischenablage zu kopieren, die Pappe zwei Arten enthält:
"public.text",
"Apple Web Archive pasteboard type
Auf dieser Grundlage habe ich eine bequeme Kategorie auf UIPasteboard.
(Bei starker Verwendung von Code aus this answer).
Es funktioniert, aber:
Die Konvertierung in HTML-Format bedeutet, dass ich benutzerdefinierte Attribute verlieren werde. Jede saubere Lösung wird gerne angenommen.
Datei UIPasteboard + AttributedString.h:
@interface UIPasteboard (AttributedString)
- (void) setAttributedString:(NSAttributedString *)attributedString;
@end
Datei UIPasteboard + AttributedString.m:
#import <MobileCoreServices/UTCoreTypes.h>
#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
Nur implementiert Setter. Wenn du den Getter schreiben und/oder ihn auf GitHub schreiben willst, sei mein Gast :)
machte einige Einblicke in UIPasteBoard und NSAttributedString könnte wertvoll sein: http://stackoverflow.com/a/38211885/1054573 –