6

UITextView で試してみました。しかし、CATextLayerを使用すると画像が空白のままになりました。

誰かが前に試しましたか?

UIView drawRect で試したコードは次のとおりです

NSTextAttachment* attachment = [NSTextAttachment new];
attachment.image = [UIImage imageNamed:@"rainbow.png"];
NSAttributedString* imageString = [NSAttributedString attributedStringWithAttachment:attachment];
NSDictionary * attribute = @{NSFontAttributeName: [UIFont fontWithName:@"Helvetica" size:12]};
NSMutableAttributedString *speechString = [[NSMutableAttributedString alloc] initWithString: @"hi" attributes:attribute];
[speechString insertAttributedString:imageString atIndex:1];
[speechString appendAttributedString:imageString];

次に CATextLayer に追加します

CATextLayer * speechTextLayer = [CATextLayer layer];
[speechTextLayer setString:speechString];
[speechTextLayer setFrame:self.bounds];
[speechTextLayer setBackgroundColor:[UIColor whiteColor].CGColor];
[self.layer addSublayer:speechTextLayer];
4

0 に答える 0