How do you use NSAttributedString?

后端 未结 15 1125
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 04:19

Multiple colours in an NSString or NSMutableStrings are not possible. So I\'ve heard a little about the NSAttributedString which was introduced wit

15条回答
  •  梦如初夏
    2020-11-22 04:54

    I wrote helper to add attributes easily:

    - (void)addColor:(UIColor *)color substring:(NSString *)substring;
    - (void)addBackgroundColor:(UIColor *)color substring:(NSString *)substring;
    - (void)addUnderlineForSubstring:(NSString *)substring;
    - (void)addStrikeThrough:(int)thickness substring:(NSString *)substring;
    - (void)addShadowColor:(UIColor *)color width:(int)width height:(int)height radius:(int)radius substring:(NSString *)substring;
    - (void)addFontWithName:(NSString *)fontName size:(int)fontSize substring:(NSString *)substring;
    - (void)addAlignment:(NSTextAlignment)alignment substring:(NSString *)substring;
    - (void)addColorToRussianText:(UIColor *)color;
    - (void)addStrokeColor:(UIColor *)color thickness:(int)thickness substring:(NSString *)substring;
    - (void)addVerticalGlyph:(BOOL)glyph substring:(NSString *)substring;
    

    https://github.com/shmidt/MASAttributes

    You can install through CocoaPods also : pod 'MASAttributes', '~> 1.0.0'

提交回复
热议问题