zoukankan      html  css  js  c++  java
  • NSMutableAttributedString的使用

    有时候我们写UI的时候经常会遇到这样的情况  就是图片和文字离的较近  或者文字排版在一行但是字体大小或者颜色不一样 这时候如果写不同的Label或者是不同的控件就会很麻烦 。 我们经常会使用NSMutableAttributedString来简化

    总结经常使用的NSMutableAttributedString一些样式

         NSFontAttributeName;(字体)

         NSParagraphStyleAttributeName;(段落)

         NSForegroundColorAttributeName;(字体颜色)

         NSBackgroundColorAttributeName;(字体背景色)

         NSLigatureAttributeName;(连字符)

         NSKernAttributeName;(字间距)

         NSStrikethroughStyleAttributeName;(删除线) 

         NSUnderlineStyleAttributeName;(下划线) 

         NSStrokeColorAttributeName;(边线颜色)

         NSStrokeWidthAttributeName;(边线宽度) 

         NSShadowAttributeName;(阴影)(横竖排版)

         NSFontAttributeName;(字体)
         NSParagraphStyleAttributeName;(段落)
         NSForegroundColorAttributeName;(字体颜色)
         NSBackgroundColorAttributeName;(字体背景色)
         NSLigatureAttributeName;(连字符)
         NSKernAttributeName;(字间距)
         NSStrikethroughStyleAttributeName;(删除线) 
         NSUnderlineStyleAttributeName;(下划线) 
         NSStrokeColorAttributeName;(边线颜色)
         NSStrokeWidthAttributeName;(边线宽度) 
         NSShadowAttributeName;(阴影)(横竖排版)
    
    //图文混排
        NSMutableAttributedString *attText =[[NSMutableAttributedString alloc] init];
    //设置文本样式
        NSMutableDictionary *dic1 =[NSMutableDictionary dictionary];
        dic1[NSUnderlineStyleAttributeName] =@1;
        NSAttributedString *first =[[NSAttributedString alloc] initWithString:@"hello" attributes:dic1];
        [attText appendAttributedString:first];
    //设置文本样式
        NSMutableDictionary *dic =[NSMutableDictionary dictionary];
        dic[NSFontAttributeName] =[UIFont systemFontOfSize:20];
        
        dic[NSForegroundColorAttributeName] =[UIColor orangeColor];
        NSAttributedString *third =[[NSAttributedString alloc] initWithString:@"这是一个实验" attributes:dic];
        [attText appendAttributedString:third];
        
        label.attributedText =attText;
    
    可以用这个NSTextAttachment类来设置图片和文字的混合添加  
    
    NSTextAttachment *text =[[NSTextAttachment alloc] init];
        text.image =[UIImage imageNamed:@"视频1.png"];
    
  • 相关阅读:
    spring boot 中使用redis session
    关于 JVM 内存的 N 个问题(转)
    在JAVA中记录日志的十个小建议
    spring boot jpa 多数据源配置
    python高性能web框架——Japronto
    毕业 3 年,为何技术能力相差越来越大?——转自阿里技术人生
    如何成为技术大牛——阿里CodeLife
    布式之数据库和缓存双写一致性方案解析(转)
    海量数据存储--分库分表策略详解 (转)
    Linux内核模块简单示例
  • 原文地址:https://www.cnblogs.com/wangxiaoqi/p/6407912.html
Copyright © 2011-2022 走看看