• iOS --有行距的图文混排


    UILabel *label = [[UILabel alloc]init];
    
        label.numberOfLines = 0;
    
        [self.view addSubview:label];
    
        label.backgroundColor = [UIColor grayColor];
    
        label.textColor = [UIColor redColor];
    
        
    
        NSMutableAttributedString *attisstr = [[NSMutableAttributedString alloc]initWithString:@"版权声明:本文为博主原创文章,未经博主允许不得转载。    http://www.cnblogs.com/shenlaiyaoshi/版权声明:本文为博主原创文章,未经博主允许不得转载。    http://www.cnblogs.com/shenlaiyaoshi/"];
    
        
    
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    
        dict[NSFontAttributeName] = [UIFont systemFontOfSize:15];
    
        
    
        NSMutableParagraphStyle *parstype = [[NSMutableParagraphStyle alloc]init];
    
        parstype.lineSpacing = 15;
    
        dict[NSParagraphStyleAttributeName] = parstype;
    
        
    
        NSTextAttachment *attachment = [[NSTextAttachment alloc]init];
    
        attachment.image = [UIImage imageNamed:@"1533291758"];
    
        attachment.bounds= CGRectMake(0, -17, 40, 40);
    
        NSAttributedString *stringsimage = [NSAttributedString attributedStringWithAttachment:attachment];;
    
        [attisstr insertAttributedString:stringsimage atIndex:3];
    
        dict[NSAttachmentAttributeName] = attachment;
    
        label.attributedText = [[NSAttributedString alloc]initWithString:[attisstr string] attributes:dict];
    
        
    
        [label sizeToFit];

     

  • 相关阅读:
    mysql分页查询语法
    不同浏览器CSS样式不兼容问题
    js引入jquery问题
    ElasticSearcher的安装以及安装过程中出现的问题
    Mybites逆向工程的搭建
    Maven遇到的各种问题
    Maven安装和配置
    Maven报错:Unsupported major.minor version 51.0
    teamviewer远程是账号密码都没错但是报正在初始化参数...
    远程服务器时无密码登录
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/9465076.html
Copyright © 2020-2023  润新知