非常に単純な RTF ファイルである出力がいくつかあります。このドキュメントを生成すると、ユーザーはそれを電子メールで送信できます。これはすべて正常に機能します。ドキュメントはよさそうです。NSAttributedString を取得したら、NSData ブロックを作成し、次のようにファイルに書き込みます。
NSData* rtfData = [attrString dataFromRange:NSMakeRange(0, [attrString length]) documentAttributes:@{NSDocumentTypeDocumentAttribute: NSRTFTextDocumentType} error:&error];
このファイルは電子メールで送信できます。メールをチェックすると、すべて問題ありません。
今、私はドキュメントの上部にuiimageを追加する任務を負っています。すばらしいので、次のような属性付き文字列を作成しています。
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
UIImage* image = [UIImage imageNamed:@"logo"];
attachment.image = image;
attachment.bounds = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
NSMutableAttributedString *imageAttrString = [[NSAttributedString attributedStringWithAttachment:attachment] mutableCopy];
// sets the paragraph styling of the text attachment
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init] ;
[paragraphStyle setAlignment:NSTextAlignmentCenter]; // centers image horizontally
[paragraphStyle setParagraphSpacing:10.0f]; // adds some padding between the image and the following section
[imageAttrString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [imageAttrString length])];
[imageAttrString appendAttributedString:[[NSAttributedString alloc] initWithString:@"\n\n"]];
この時点で、Xcodeでは、ImageAtstringをすばやく展示することができます。
この文字列が作成されたら、次のようにします。
[attrString appendAttributedString:imageAttrString];
そして、私が元々生成したすべての属性テキストをすべて追加します。
今ファイルを見てみると、画像がありません。デバッガーでは QuickLook は問題ないように見えますが、最終出力には画像がありません。
これについてご協力いただきありがとうございます。