UILabel中插入图片

    NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"1234567" attributes:nil];

    NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
    UIImage * smileImage = [UIImage imageNamed:@"ddd.png"];
    textAttachment.image = smileImage;

    NSAttributedString *textAttachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
    [string insertAttributedString:textAttachmentString atIndex:0];

    mlbText.attributedText = string;

 

你可能感兴趣的:(iOS)