• 图文混排(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;

  • 相关阅读:
    C#构造函数
    C#析构函数
    C#常量
    C#属性
    checklistbox的用法
    2012快捷键
    查询ORACLE存储关联表
    UltraDropDown
    Linux常用命令大全(非常全!!!)
    infra 仪表盘效果
  • 原文地址:https://www.cnblogs.com/kingtoKing/p/5658513.html
Copyright © 2020-2023  润新知