-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '1e340b69c6c31a670be80596b59ad712c684213f’(pr/7)
# Conflicts: # TXScrollLabelViewDemo/TXScrollLabelViewDemo/ViewController.m
- Loading branch information
Showing
5 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
TXScrollLabelViewDemo/TXScrollLabelViewDemo/NSString+AttributedString.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// NSString+AttributedString.h | ||
// TXScrollLabelViewDemo | ||
// | ||
// Created by 陈应平 on 2016/12/5. | ||
// Copyright © 2016年 tingxins. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface NSString (AttributedString) | ||
|
||
// 传递一个字符串数组,可以渲染不同的颜色,后期有需要可以把 color 和 font 也以数组的形式传递,配对使用 | ||
- (NSMutableAttributedString *)setAttributedWithIdentifyStringArray:(NSArray *)identifyStringArray color:(UIColor *)color font:(UIFont *)font; | ||
|
||
@end |
37 changes: 37 additions & 0 deletions
37
TXScrollLabelViewDemo/TXScrollLabelViewDemo/NSString+AttributedString.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// NSString+AttributedString.m | ||
// TXScrollLabelViewDemo | ||
// | ||
// Created by 陈应平 on 2016/12/5. | ||
// Copyright © 2016年 tingxins. All rights reserved. | ||
// | ||
|
||
#import "NSString+AttributedString.h" | ||
|
||
@implementation NSString (AttributedString) | ||
|
||
- (NSMutableAttributedString *)setAttributedWithIdentifyStringArray:(NSArray *)identifyStringArray color:(UIColor *)color font:(UIFont *)font | ||
{ | ||
if (!self && !identifyStringArray) { | ||
return nil; | ||
} | ||
|
||
if (!identifyStringArray.count) { | ||
return nil; | ||
} | ||
|
||
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc]initWithString:self]; | ||
for (NSString *identifyString in identifyStringArray) { | ||
NSRange range = [self rangeOfString:identifyString]; | ||
if (font) { | ||
[attributedStr addAttribute:NSFontAttributeName value:font range:range]; | ||
} | ||
if (color) { | ||
[attributedStr addAttribute:NSForegroundColorAttributeName value:color range:range]; | ||
} | ||
} | ||
|
||
return attributedStr; | ||
} | ||
|
||
@end |