zoukankan      html  css  js  c++  java
  • 字符串属性 NSMutableAttributedString/NSAttributedString

    因为iOS7新出的NSTextStorge是NSMutableAttributedString的子类。所以要用好NSTextStorage。首先要学好NSMutableAttributedString和NSAttributedString。

    按个人的理解。NSAttributedString是一个带有属性的字符串,通过该类能够灵活地操作和呈现多种样式的文字数据。


      alignment //对齐方式
      firstLineHeadIndent //首行缩进
      headIndent //缩进
      tailIndent  //尾部缩进
      lineBreakMode  //断行方式
      maximumLineHeight  //最大行高
      minimumLineHeight  //最低行高
      lineSpacing  //行距
      paragraphSpacing  //段距
      paragraphSpacingBefore  //段首空间
      baseWritingDirection  //句子方向
      lineHeightMultiple  //可变行高,乘因数。


      hyphenationFactor //连字符属性
    NSString *const NSForegroundColorAttributeName;//值为UIColor,字体颜色,默觉得黑色。


    NSString *const NSBackgroundColorAttributeName;//值为UIColor。字体背景色,默认没有。


    NSString *const NSLigatureAttributeName;//值为整型NSNumber,连字属性,一般中文用不到。在英文中可能出现相邻字母连笔的情况。0为不连笔。1为默认连笔。也是默认值。2在ios 上不支持。


    NSString *const NSKernAttributeName;//值为浮点数NSNumber,字距属性,默认值为0。




    NSString *const NSStrikethroughStyleAttributeName;//值为整型NSNumber。可取值为


    enum {


    NSUnderlineStyleNone = 0×00,


    NSUnderlineStyleSingle = 0×01,


    };设置删除线。


    NSString *const NSUnderlineStyleAttributeName;//同上。设置下划线。


    NSString *const NSStrokeColorAttributeName;//值为UIColor。默认值为nil,设置的属性同ForegroundColor。


    NSString *const NSStrokeWidthAttributeName;//值为浮点数NSNumber。

    设置比画的粗细。


    NSString *const NSShadowAttributeName;//值为NSShadow,设置比画的阴影。默认值为nil。


    NSString *const NSVerticalGlyphFormAttributeName;//值为整型NSNumber,0为水平排版的字,1为垂直排版的字。


    演示样例代码:

    //label上加入删除线

    <span style="font-family:Comic Sans MS;font-size:18px;">    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
        
        label.text = @"zuoyou1314";
        
        NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:@"zuoyou1314"];
        [str addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInt: NSUnderlineStyleSingle] range:NSMakeRange(0, str.length)];
        label.attributedText = str;
        [self.window addSubview:label];</span>
    //设置下划线

     NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@"Some String"]; 
    [attString addAttribute:(NSString*)kCTUnderlineStyleAttributeName value:[NSNumber numberWithInt:kCTUnderlineStyleSingle] range:(NSRange){0,[attString length]}];
     self.myLabel.attributedText = attString;





    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    vss
    JavaScript中的5种事件使用方式解说
    loadrunner
    NET体系结构图
    eclipse Java Build Path
    httpModules 与 httpHandlers
    redhat linux5 安装配置 JDK1.6+Tomcat6+Apache2.2.x+jk_mod1.2
    如何在线使用MSDN
    petshop
    ADO.NET Entity Framework 使用数据定义语言(实体框架)
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4806544.html
Copyright © 2011-2022 走看看