zoukankan      html  css  js  c++  java
  • 图文混排(2) 详解版

     // 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;

  • 相关阅读:
    离场飞越转弯全家福
    画一个PBN大角度飞越转弯保护区
    画一个小角度飞越转弯保护区
    Point Estimation
    Random variable
    心流
    Survey sampling
    Distribution
    数学分析总结
    topological space
  • 原文地址:https://www.cnblogs.com/kingtoKing/p/5658513.html
Copyright © 2011-2022 走看看