Skip to content

Commit

Permalink
Merge commit '1e340b69c6c31a670be80596b59ad712c684213f’(pr/7)
Browse files Browse the repository at this point in the history
# Conflicts:
#	TXScrollLabelViewDemo/TXScrollLabelViewDemo/ViewController.m
  • Loading branch information
tingxins committed Dec 5, 2016
2 parents 2956ba5 + 1e340b6 commit f833149
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions TXScrollLabelView/TXScrollLabelView.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ typedef NS_ENUM(NSInteger, TXScrollLabelViewType) {
//根据内容自适应宽度 Pending!!
@property (assign, nonatomic) BOOL autoWidth;

#pragma mark - setupAttributeTitle

- (void)setupAttributeTitle:(NSAttributedString *)attributeTitle;

#pragma mark - Class Methods

Expand Down
7 changes: 7 additions & 0 deletions TXScrollLabelView/TXScrollLabelView.m
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ - (void)setupTitle:(NSString *)title {
self.downLabel.text = title;
}

- (void)setupAttributeTitle:(NSAttributedString *)attributeTitle {
_scrollTitle = attributeTitle.string;
[self setupSubviewsLayout];
self.upLabel.attributedText = attributeTitle;
self.downLabel.attributedText = attributeTitle;
}

- (void)setupRepeatTypeLayout {
CGFloat labelW = self.tx_width - _scrollInset.left - _scrollInset.right;
CGFloat labelX = _scrollInset.left;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
97886DA71DB8E0AF00A0B326 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97886DA51DB8E0AF00A0B326 /* LaunchScreen.storyboard */; };
97886DB21DB8E0AF00A0B326 /* TXScrollLabelViewDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 97886DB11DB8E0AF00A0B326 /* TXScrollLabelViewDemoTests.m */; };
97886DBD1DB8E0AF00A0B326 /* TXScrollLabelViewDemoUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 97886DBC1DB8E0AF00A0B326 /* TXScrollLabelViewDemoUITests.m */; };
AF1B25351DF5803200AB8923 /* NSString+AttributedString.m in Sources */ = {isa = PBXBuildFile; fileRef = AF1B25341DF5803200AB8923 /* NSString+AttributedString.m */; };
/* End PBXBuildFile section */

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

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -122,6 +125,8 @@
97886D9B1DB8E0AF00A0B326 /* AppDelegate.m */,
97886D9D1DB8E0AF00A0B326 /* ViewController.h */,
97886D9E1DB8E0AF00A0B326 /* ViewController.m */,
AF1B25331DF5803200AB8923 /* NSString+AttributedString.h */,
AF1B25341DF5803200AB8923 /* NSString+AttributedString.m */,
97886DA31DB8E0AF00A0B326 /* Assets.xcassets */,
97886DA51DB8E0AF00A0B326 /* LaunchScreen.storyboard */,
97886DA81DB8E0AF00A0B326 /* Info.plist */,
Expand Down Expand Up @@ -295,6 +300,7 @@
972620CA1DDE2F0600009F23 /* TXScrollLabelView.m in Sources */,
97886D9F1DB8E0AF00A0B326 /* ViewController.m in Sources */,
97886D9C1DB8E0AF00A0B326 /* AppDelegate.m in Sources */,
AF1B25351DF5803200AB8923 /* NSString+AttributedString.m in Sources */,
97886D991DB8E0AF00A0B326 /* main.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
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
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

0 comments on commit f833149

Please sign in to comment.