zoukankan      html  css  js  c++  java
  • 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];

     

  • 相关阅读:
    linux docker常用命令
    angular input输入框自动消除前后空格
    angular 一览数据全选符合条件数据
    linux MySQL出现错误的一些常见解决办法
    linux crontab定时任务一些命令
    Linux下定时访问指定url地址
    直接打印对象的结果
    java中变量的作用域
    请求转发后地址栏显示传入的值,页面不显示的原因
    String不是基本数据类型,但是
  • 原文地址:https://www.cnblogs.com/shenlaiyaoshi/p/9465076.html
Copyright © 2011-2022 走看看