美文网首页iOS菜鸟级开发iOS学习
iOS开发--NSAttributedString

iOS开发--NSAttributedString

作者: JohnnyB0Y | 来源:发表于2015-09-02 04:25 被阅读4499次

    这是我个人的学习笔记 , 如有不同见解欢迎评论交流 .
    ( 我的微博 : http://weibo.com/JohnnyB0Y )

    今天弄Quartz 2D的时候,测试文字绘制,遇到了不具名的字典。根据 NSAttributedString.h 里关于文字效果属性字典常用的key值, 顺手都试了一下,以下是详细报道。

    Predefined character attributes for text. If the key is not in the dictionary, then use the default values as described below.

    • 设置字体的字符串常量
    UIKIT_EXTERN NSString *const NSFontAttributeName NS_AVAILABLE_IOS(6_0);

    // UIFont, default Helvetica(Neue) 12


    • 设置文字段落的字符串常量 (文字段落框要有宽度和高度才有效果)
    UIKIT_EXTERN NSString *const NSParagraphStyleAttributeName NS_AVAILABLE_IOS(6_0);

    // NSParagraphStyle, default defaultParagraphStyle


    • 设置文字颜色
    UIKIT_EXTERN NSString *const NSForegroundColorAttributeName NS_AVAILABLE_IOS(6_0);

    // UIColor, default blackColor


    • 设置文字背景框的颜色
    UIKIT_EXTERN NSString *const NSBackgroundColorAttributeName NS_AVAILABLE_IOS(6_0);

    // UIColor, default nil: no background


    • 设置连体文字
    UIKIT_EXTERN NSString *const NSLigatureAttributeName NS_AVAILABLE_IOS(6_0);

    // NSNumber containing integer, default 1: default ligatures, 0: no ligatures


    • 设置文字间的距离,0代表关闭使用(测试得到正数分开,负数重叠)
    UIKIT_EXTERN NSString *const NSKernAttributeName NS_AVAILABLE_IOS(6_0);

    // NSNumber containing floating point value, in points; amount to modify default kerning. 0 means kerning is disabled.


    • 设置文字删除线样式
    UIKIT_EXTERN NSString *const NSStrikethroughStyleAttributeName NS_AVAILABLE_IOS(6_0);

    // NSNumber containing integer, default 0: no strikethrough


    • 设置文字下划线样式
    UIKIT_EXTERN NSString *const NSUnderlineStyleAttributeName NS_AVAILABLE_IOS(6_0);

    // NSNumber containing integer, default 0: no underline


    • 设置文字笔画颜色
    UIKIT_EXTERN NSString *const NSStrokeColorAttributeName NS_AVAILABLE_IOS(6_0);

    // UIColor, default nil: same as foreground color


    • 设置文字笔画宽度的百分比(类似于空心文字)
    UIKIT_EXTERN NSString *const NSStrokeWidthAttributeName NS_AVAILABLE_IOS(6_0);

    // NSNumber containing floating point value, in percent of font point size, default 0: no stroke; positive for stroke alone, negative for stroke and fill (a typical value for outlined text would be 3.0)


    • 设置文字的阴影属性
    UIKIT_EXTERN NSString *const NSShadowAttributeName NS_AVAILABLE_IOS(6_0);

    // NSShadow, default nil: no shadow


    • 设置文本效果
    UIKIT_EXTERN NSString *const NSTextEffectAttributeName NS_AVAILABLE_IOS(7_0);

    // NSString, default nil: no text effect


    • 设置文字附件属性(图文混排相关)
    UIKIT_EXTERN NSString *const NSAttachmentAttributeName NS_AVAILABLE_IOS(7_0);

    // NSTextAttachment, default nil


    • 设置文字的网络链接效果
    UIKIT_EXTERN NSString *const NSLinkAttributeName NS_AVAILABLE_IOS(7_0);

    // NSURL (preferred) or NSString


    • 设置文字基线偏移量
    UIKIT_EXTERN NSString *const NSBaselineOffsetAttributeName NS_AVAILABLE_IOS(7_0);

    // NSNumber containing floating point value, in points; offset from baseline, default 0


    • 设置文字下划线颜色
    UIKIT_EXTERN NSString *const NSUnderlineColorAttributeName NS_AVAILABLE_IOS(7_0);

    // UIColor, default nil: same as foreground color


    • 设置文字删除线颜色
    UIKIT_EXTERN NSString *const NSStrikethroughColorAttributeName NS_AVAILABLE_IOS(7_0);

    // UIColor, default nil: same as foreground color


    • 设置字体歪斜效果
    UIKIT_EXTERN NSString *const NSObliquenessAttributeName NS_AVAILABLE_IOS(7_0);

    // NSNumber containing floating point value; skew to be applied to glyphs, default 0: no skew


    • 设置文字向左右拉伸(正数),向中间缩小(负数)
    UIKIT_EXTERN NSString *const NSExpansionAttributeName NS_AVAILABLE_IOS(7_0);

    // NSNumber containing floating point value; log of expansion factor to be applied to glyphs, default 0: no expansion


    • 设置文字的书写样式
    UIKIT_EXTERN NSString *const NSWritingDirectionAttributeName NS_AVAILABLE_IOS(7_0);

    // NSArray of NSNumbers representing the nested levels of writing direction overrides as defined by Unicode LRE, RLE, LRO, and RLO characters.
    The control characters can be obtained by masking NSWritingDirection and NSTextWritingDirection values.
    LRE: NSWritingDirectionLeftToRight|NSTextWritingDirectionEmbedding,
    RLE: NSWritingDirectionRightToLeft|NSTextWritingDirectionEmbedding,
    LRO: NSWritingDirectionLeftToRight|NSTextWritingDirectionOverride,
    RLO: NSWritingDirectionRightToLeft|NSTextWritingDirectionOverride,


    • 设置文字的垂直符号样式(测试只对中文标点起作用,0标点靠左,1标点靠右)
    UIKIT_EXTERN NSString *const NSVerticalGlyphFormAttributeName NS_AVAILABLE_IOS(6_0);

    // An NSNumber containing an integer value. 0 means horizontal text.
    1 indicates vertical text.
    If not specified, it could follow higher-level vertical orientation settings.
    Currently on iOS, it's always horizontal.
    The behavior for any other value is undefined.

    相关文章

      网友评论

        本文标题:iOS开发--NSAttributedString

        本文链接:https://www.haomeiwen.com/subject/akdlcttx.html