图文混排的简单使用

图片和文字的简单混排主要实现是 NSTextAttachment类的使用


    NSMutableAttributedString *muString = [[NSMutableAttributedStringalloc]init];

// Key parts of image insertion

    NSTextAttachment *attenment = [[NSTextAttachmentalloc]init];

    attenment.image = [UIImageimageNamed:@"a_ss_a.png"];

    attenment.bounds =CGRectMake(0, -5,17,17);

    NSAttributedString *gift = [NSAttributedStringattributedStringWithAttachment:attenment];

    [muString appendAttributedString:gift];


我写了一个小Demo放在GitHub上了,地址是https://github.com/GHshanshan/TextWithImage

文中附赠改变文字颜色,主动换行的实现,行间距的设置

运行效果如下:

 

猜你喜欢

转载自blog.csdn.net/a_ss_a/article/details/51614249