zoukankan      html  css  js  c++  java
  • iOS UILable 文字添加图片 (文字前面,中间,后面添加图)

    1,实例化一个UILable

    2,

     // 创建一个富文本

        NSMutableAttributedString *attri =     [[NSMutableAttributedString alloc] initWithString:@"超时罚款24元/小时"];

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

        // 表情图片

        attch.image = [UIImage imageNamed:@"parking_caveat_normal"];

        // 设置图片大小

        attch.bounds = CGRectMake(0, 0, 30/2, 27/2);

        // 创建带有图片的富文本

        NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];

    [attri appendAttributedString:string]; //在文字后面添加图片

     //在文字下标第几个添加图片  0就是文字前面添加图片

          [attri insertAttributedString:string atIndex:0]; 

        // 用label的attributedText属性来使用富文本

        实例化的lable.attributedText = attri;

  • 相关阅读:
    Python基础-序列化模块
    dubbox
    小型供销系统
    MyBatis与SpringBoot整合案例(一)
    SpringBoot第二节
    SpringBoot第一节
    Dubbo案例SSM整合
    Dubbo生产者和消费者
    Zookeeper实战分布式锁
    Zookeeper Watcher和选举机制
  • 原文地址:https://www.cnblogs.com/liaolijun/p/7601022.html
Copyright © 2011-2022 走看看