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;

  • 相关阅读:
    c#反射动态创建窗体
    ImageSwitcher 图片切换器
    viewSwitcher 切换视图
    ratingBar 星级评分条
    seekBar拖动滑块
    pythonUDP发送结构体,对齐到C++结构体
    pyqt5界面
    progressbar
    SVN服务器搭建和使用(一)
    关于MBR、GPT以及BIOS引导模式区分
  • 原文地址:https://www.cnblogs.com/kingtoKing/p/5658513.html
Copyright © 2011-2022 走看看