• NSAttributedString


    NSAttributedString维护了一个NSString,用来保存最原始的字符串,另有一个NSDictionary用来保存各个子串/字符的属性。

    创建AttributedString演示样例:
    UIFont *font = [UIFont fontWithName:@"Courier" size:18.0];
    NSDictionary *attriDict = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName];
    NSAttributedString *attriStr = [[NSAttributedString alloc] initWithString:@"my attributed string" attributes:attriDict];
    self.label.attributedText = attriStr;

    一些常见属性:
    字体
    UIKIT_EXTERN NSString *const NSFontAttributeName NS_AVAILABLE_IOS(6_0);                // UIFont, default Helvetica(Neue) 12

    文字颜色, 前景色
    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

    // strike-through line 中划线
    UIKIT_EXTERN NSString *const NSStrikethroughStyleAttributeName NS_AVAILABLE_IOS(6_0);  // NSNumber containing integer, default 0: no strikethrough

    // strike-though line 颜色
    UIKIT_EXTERN NSString *const NSStrikethroughColorAttributeName NS_AVAILABLE_IOS(7_0);  // UIColor, default nil: same as foreground color

    // underline-style 下划线
    UIKIT_EXTERN NSString *const NSUnderlineStyleAttributeName NS_AVAILABLE_IOS(6_0);      // NSNumber containing integer, default 0: no underline

    // 下划线颜色
    UIKIT_EXTERN NSString *const NSUnderlineColorAttributeName NS_AVAILABLE_IOS(7_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
         NSShadow *shadow = [[NSShadow alloc] init];
        shadow.shadowBlurRadius = 5;  // 模糊度
        shadow.shadowColor = [UIColor blackColor];
        shadow.shadowOffset = CGSizeMake(1, 3);
        NSShadowAttributeName:shadow

    倾斜
    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
  • 相关阅读:
    day29 Pyhton 面向对象 继承进阶
    UX&UI的介绍区别
    APP设计中“登录”按钮的高度多少才好呢?经验总结!
    新人与三年经验的交互设计师有多大的差距?
    UI设计师是混哪一块?要做什么?图文结合详解
    是时候重新审视正在流行的卡片设计趋势了!
    图表设计的介绍及指导
    完整的交互设计流程应该是怎样的?
    设计师如何用产品思维提升用户体验?
    2015年最流行的渐变技巧!
  • 原文地址:https://www.cnblogs.com/lxjshuju/p/7183981.html
Copyright © 2020-2023  润新知