Skip to content

Commit f833149

Browse files
committed
Merge commit '1e340b69c6c31a670be80596b59ad712c684213f’(pr/7)
# Conflicts: # TXScrollLabelViewDemo/TXScrollLabelViewDemo/ViewController.m
2 parents 2956ba5 + 1e340b6 commit f833149

File tree

5 files changed

+69
-0
lines changed

5 files changed

+69
-0
lines changed

TXScrollLabelView/TXScrollLabelView.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ typedef NS_ENUM(NSInteger, TXScrollLabelViewType) {
6464
//根据内容自适应宽度 Pending!!
6565
@property (assign, nonatomic) BOOL autoWidth;
6666

67+
#pragma mark - setupAttributeTitle
68+
69+
- (void)setupAttributeTitle:(NSAttributedString *)attributeTitle;
6770

6871
#pragma mark - Class Methods
6972

TXScrollLabelView/TXScrollLabelView.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ - (void)setupTitle:(NSString *)title {
352352
self.downLabel.text = title;
353353
}
354354

355+
- (void)setupAttributeTitle:(NSAttributedString *)attributeTitle {
356+
_scrollTitle = attributeTitle.string;
357+
[self setupSubviewsLayout];
358+
self.upLabel.attributedText = attributeTitle;
359+
self.downLabel.attributedText = attributeTitle;
360+
}
361+
355362
- (void)setupRepeatTypeLayout {
356363
CGFloat labelW = self.tx_width - _scrollInset.left - _scrollInset.right;
357364
CGFloat labelX = _scrollInset.left;

TXScrollLabelViewDemo/TXScrollLabelViewDemo.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
97886DA71DB8E0AF00A0B326 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97886DA51DB8E0AF00A0B326 /* LaunchScreen.storyboard */; };
1717
97886DB21DB8E0AF00A0B326 /* TXScrollLabelViewDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 97886DB11DB8E0AF00A0B326 /* TXScrollLabelViewDemoTests.m */; };
1818
97886DBD1DB8E0AF00A0B326 /* TXScrollLabelViewDemoUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 97886DBC1DB8E0AF00A0B326 /* TXScrollLabelViewDemoUITests.m */; };
19+
AF1B25351DF5803200AB8923 /* NSString+AttributedString.m in Sources */ = {isa = PBXBuildFile; fileRef = AF1B25341DF5803200AB8923 /* NSString+AttributedString.m */; };
1920
/* End PBXBuildFile section */
2021

2122
/* Begin PBXContainerItemProxy section */
@@ -55,6 +56,8 @@
5556
97886DB81DB8E0AF00A0B326 /* TXScrollLabelViewDemoUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TXScrollLabelViewDemoUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
5657
97886DBC1DB8E0AF00A0B326 /* TXScrollLabelViewDemoUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TXScrollLabelViewDemoUITests.m; sourceTree = "<group>"; };
5758
97886DBE1DB8E0AF00A0B326 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
59+
AF1B25331DF5803200AB8923 /* NSString+AttributedString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+AttributedString.h"; sourceTree = "<group>"; };
60+
AF1B25341DF5803200AB8923 /* NSString+AttributedString.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+AttributedString.m"; sourceTree = "<group>"; };
5861
/* End PBXFileReference section */
5962

6063
/* Begin PBXFrameworksBuildPhase section */
@@ -122,6 +125,8 @@
122125
97886D9B1DB8E0AF00A0B326 /* AppDelegate.m */,
123126
97886D9D1DB8E0AF00A0B326 /* ViewController.h */,
124127
97886D9E1DB8E0AF00A0B326 /* ViewController.m */,
128+
AF1B25331DF5803200AB8923 /* NSString+AttributedString.h */,
129+
AF1B25341DF5803200AB8923 /* NSString+AttributedString.m */,
125130
97886DA31DB8E0AF00A0B326 /* Assets.xcassets */,
126131
97886DA51DB8E0AF00A0B326 /* LaunchScreen.storyboard */,
127132
97886DA81DB8E0AF00A0B326 /* Info.plist */,
@@ -295,6 +300,7 @@
295300
972620CA1DDE2F0600009F23 /* TXScrollLabelView.m in Sources */,
296301
97886D9F1DB8E0AF00A0B326 /* ViewController.m in Sources */,
297302
97886D9C1DB8E0AF00A0B326 /* AppDelegate.m in Sources */,
303+
AF1B25351DF5803200AB8923 /* NSString+AttributedString.m in Sources */,
298304
97886D991DB8E0AF00A0B326 /* main.m in Sources */,
299305
);
300306
runOnlyForDeploymentPostprocessing = 0;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// NSString+AttributedString.h
3+
// TXScrollLabelViewDemo
4+
//
5+
// Created by 陈应平 on 2016/12/5.
6+
// Copyright © 2016年 tingxins. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface NSString (AttributedString)
12+
13+
// 传递一个字符串数组,可以渲染不同的颜色,后期有需要可以把 color 和 font 也以数组的形式传递,配对使用
14+
- (NSMutableAttributedString *)setAttributedWithIdentifyStringArray:(NSArray *)identifyStringArray color:(UIColor *)color font:(UIFont *)font;
15+
16+
@end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// NSString+AttributedString.m
3+
// TXScrollLabelViewDemo
4+
//
5+
// Created by 陈应平 on 2016/12/5.
6+
// Copyright © 2016年 tingxins. All rights reserved.
7+
//
8+
9+
#import "NSString+AttributedString.h"
10+
11+
@implementation NSString (AttributedString)
12+
13+
- (NSMutableAttributedString *)setAttributedWithIdentifyStringArray:(NSArray *)identifyStringArray color:(UIColor *)color font:(UIFont *)font
14+
{
15+
if (!self && !identifyStringArray) {
16+
return nil;
17+
}
18+
19+
if (!identifyStringArray.count) {
20+
return nil;
21+
}
22+
23+
NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc]initWithString:self];
24+
for (NSString *identifyString in identifyStringArray) {
25+
NSRange range = [self rangeOfString:identifyString];
26+
if (font) {
27+
[attributedStr addAttribute:NSFontAttributeName value:font range:range];
28+
}
29+
if (color) {
30+
[attributedStr addAttribute:NSForegroundColorAttributeName value:color range:range];
31+
}
32+
}
33+
34+
return attributedStr;
35+
}
36+
37+
@end

0 commit comments

Comments
 (0)