首页 > 其他 > 详细

图文混排(2) 详解版

时间:2016-07-10 21:31:33      阅读:208      评论:0      收藏:0      [点我收藏+]

 // 1> Attachment - 附件

    NSTextAttachment *attachment = [[NSTextAttachment alloc] init];

    

    attachment.image = [UIImage imageNamed:@"d_aini"];

    // 提示 lineHeight 大致和字体的大小相等

    /**

     面试题

     

     请说出 frame bounds 的区别

     

     frame: x, y 决定当前控件,相对父控件的位置

     bounds: x, y 决定内部子控件想对原点的位置,就是 scrollView contentOffset!

     */

    CGFloat height = self.label.font.lineHeight;

    attachment.bounds = CGRectMake(0, -4, height, height);

    

    // 2> 图像字符串

    NSAttributedString *imageStr = [NSAttributedString attributedStringWithAttachment:attachment];

    

    // 3> 定义一个可变的属性字符串

    NSMutableAttributedString *attrStrM = [[NSMutableAttributedString alloc] initWithString:@""];

    

    // 4> 拼接图片文本

    [attrStrM appendAttributedString:imageStr];

    [attrStrM appendAttributedString:[[NSAttributedString alloc] initWithString:@"88!"]];

    

    // 设置属性文本

    self.label.attributedText = attrStrM;

图文混排(2) 详解版

原文:http://www.cnblogs.com/kingtoKing/p/5658513.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!