zoukankan      html  css  js  c++  java
  • UILabel图文混排显示图片和文字

    //传入文字 自动图片放在左边文字紧接着后排排布
    -(void)setAttrDetailLabelWithTitle:(NSString *)title
    {
        
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] init];
        // 添加表情
        NSTextAttachment *attch = [[NSTextAttachment alloc] init];
        // 表情图片
        UIImage *image =[UIImage imageNamed:@"zp"];
            image = [UIImage imageWithCGImage:image.CGImage scale:2 orientation:UIImageOrientationUp];
        
        attch.image = image;
        
        // 设置图片大小 和 微调图片的位置
        attch.bounds = CGRectMake(0, -2, image.size.width, image.size.height);
        
        // 创建带有图片的富文本
        NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
        [attri appendAttributedString:string];
        
        [attri appendAttributedString:[[NSAttributedString alloc] initWithString:@" "]];
    
        [attri appendAttributedString:[[NSAttributedString alloc] initWithString:title]];
        
        // 用label的attributedText属性来使用富文本
        self.despLabel.attributedText = attri;
    }
    
    
    
  • 相关阅读:
    mongdb
    网络编程
    分布式锁与事务
    mongodb
    Angular4
    思考
    kafka
    Spark总结
    你不知道的javaScript笔记(1)
    vue2.0 配置 选项 属性 方法 事件 ——速查
  • 原文地址:https://www.cnblogs.com/qqcc1388/p/6709471.html
Copyright © 2011-2022 走看看