iOS 实现图文混排

 NSMutableAttributedString *str=[[NSMutableAttributedString alloc] initWithString:@"设置文字" attributes:nil];

      NSTextAttachment *attachment=[[NSTextAttachment alloc] initWithData:nil ofType:nil];

    UIImage *img=[UIImage imageNamed:@"图片.png"];

    attachment.image=img;

    attachment.bounds=CGRectMake(0,0, 20, 20);

    NSAttributedString *text=[NSAttributedString attributedStringWithAttachment:attachment];

      [str insertAttributedString:text atIndex:2];

    self.textView.attributedText=str;

你可能感兴趣的:(iOS,开发,Objective-C,iOS,iOS开发,图文混排)