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;





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

  • 相关阅读:
    Python,文件修改
    Python,文件
    driver.find_element_by_xpath.clear()无法清空输入框默认值
    对于隐藏性质的非标准的动态 id 的下拉框,如何定位和选中
    driver.find_element_by_xpath() 带参数时的写法
    不能聚焦元素问题 WebDriverException: Message: unknown error: cannot focus element
    firefox56 版本中的 Selenium IDE 无法导出脚本问题
    元素无法定位问题 NoSuchElementException: Message: no such element: Unable to locate element 解决方法
    selenium python 脚本不支持中文问题
    关于 chromedriver、IEDriverServer、geckodriver 驱动器的几项注意点
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4806544.html
Copyright © 2011-2022 走看看