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"];
    
  • 相关阅读:
    【6.24校内test】T1 江城唱晚
    【6.20校内test】
    【洛谷p1983】车站分级
    【洛谷p2239】螺旋矩阵
    【6.18校内test】T2分数线划定
    【6.18校内test】T1多项式输出
    【洛谷p1981】表达式求值
    【洛谷p1077】摆花
    【洛谷p1158】导弹拦截
    博客园 api
  • 原文地址:https://www.cnblogs.com/wangxiaoqi/p/6407912.html
Copyright © 2011-2022 走看看