1

baseSDK を iOS 7.1 に設定した複数の iOS 8 デバイスでプロジェクトをビルドしました。残念ながら、NSMutableAttributedString の関連するインスタンスに属性として追加されたすべての NSTextAttachment 画像は、iOS 8 デバイスおよび iOS 8 シミュレーターでは非表示になります (7.1 および iOS 7.1 シミュレーターを搭載したデバイスでは引き続き表示されます)。スーパービュー内のこれらの文字列のフレームは、画像がそこにあるかのように設定されますが、画像自体は表示またはレンダリングされません。

テキストの添付ファイルが iOS 8 で表示されないという問題に遭遇した人はいますか? もしそうなら、回避策はありますか? そうでない場合、私のコードに何か問題がありますか (以下に貼り付けます)? このインスタンスは特に UIButton の属性付きタイトルを設定しますが、同じ動作を表示している単純な UILabels である添付ファイルを持つ他のインスタンスがあります。

NSMutableAttributedString *attrButtonTitle = [[NSMutableAttributedString alloc] initWithString:@"Let's go!"];
NSTextAttachment *doubleArrowIcon = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
doubleArrowIcon.image = [UIImage imageNamed:@"double-arrows"];
[attrButtonTitle appendAttributedString:[[NSAttributedString alloc] initWithString:@"  " attributes:@{NSAttachmentAttributeName : doubleArrowIcon, NSBaselineOffsetAttributeName : @(-2)}]];
[self.nextButton setAttributedTitle:attrButtonTitle forState:UIControlStateNormal];

注: 可能であれば説明するために画像を投稿しますが、そうするための最小限のスタック オーバーフローの評判がありません。

4

2 に答える 2

2

上記のコードが 7.1 SDK でコンパイルされたときに iOS8 デバイスで画像を表示しない理由はまだわかりませんが、回避策を見つけました。テキストが添付された NSMutableAttributedString のさまざまな初期化方法を試して、仕事をするものを手に入れました。以下のコード:

NSTextAttachment *doubleArrowIcon = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
doubleArrowIcon.image = [UIImage imageNamed:@"double-arrows"];

NSAttributedString *textAttachment = [NSAttributedString attributedStringWithAttachment:doubleArrowIcon];

NSMutableAttributedString *mutableTextAttachment = [[NSMutableAttributedString alloc] initWithAttributedString:textAttachment];
[mutableTextAttachment addAttribute:NSBaselineOffsetAttributeName value:[NSNumber numberWithInt:-2] range:NSMakeRange(0, [textAttachment length])  ];
[attrButtonTitle appendAttributedString:mutableTextAttachment];
于 2014-10-03T18:57:31.720 に答える