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"];
    
  • 相关阅读:
    Android开发视频教学第一季(116集)视频&源码下载
    Android开发视频教学第一季(1734集)视频源码下载
    老罗Android开发视频教程( android解析json数据 )4集集合
    Android 亲测源码分享
    老罗Android开发视频教程 (android常用UI编程) 25集集合
    老罗Android开发视频教程 (android常用布局介绍)5集集合
    老罗Android开发视频教程 (android解析xml文件 )3集集合
    Android 开发源码分享
    基于R语言的时间序列分析预测
    .NET新手系列(六)
  • 原文地址:https://www.cnblogs.com/wangxiaoqi/p/6407912.html
Copyright © 2011-2022 走看看