Skip to content

Commit

Permalink
1.9.0 添加配置项
Browse files Browse the repository at this point in the history
  • Loading branch information
amao committed Feb 14, 2019
1 parent 58895dd commit 6046ec7
Show file tree
Hide file tree
Showing 33 changed files with 876 additions and 625 deletions.
2 changes: 1 addition & 1 deletion M80AttributedLabel.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'M80AttributedLabel'
s.version = '1.8.1'
s.version = '1.9.0'
s.authors = {'Xiang Wangfeng' => '[email protected]'}
s.homepage = 'https://github.com/xiangwangfeng/M80AttributedLabel/'
s.summary = 'Another attributed label using CoreText'
Expand Down
7 changes: 2 additions & 5 deletions M80AttributedLabel/M80AttributedLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "M80AttributedLabelDefines.h"
#import "NSMutableAttributedString+M80.h"
#import "M80AttributedLabelConfig.h"


NS_ASSUME_NONNULL_BEGIN

Expand All @@ -31,8 +33,6 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic,assign) CGFloat paragraphSpacing; //段间距
@property (nonatomic,copy,nullable) NSString *text; //普通文本
@property (nonatomic,copy,nullable) NSAttributedString *attributedText; //属性文本
@property (nonatomic,assign) NSUInteger maxSyncDetectLength; //UI 线程做 link 检查的文字最大长度



//添加文本
Expand Down Expand Up @@ -72,9 +72,6 @@ NS_ASSUME_NONNULL_BEGIN
//大小
- (CGSize)sizeThatFits:(CGSize)size;

//设置全局的自定义Link检测Block(详见M80AttributedLabelURL)
+ (void)setCustomDetectMethod:(nullable M80CustomDetectLinkBlock)block;

@end

NS_ASSUME_NONNULL_END
11 changes: 2 additions & 9 deletions M80AttributedLabel/M80AttributedLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ - (void)commonInit
_autoDetectLinks = YES;
_lineSpacing = 0.0;
_paragraphSpacing = 0.0;
_maxSyncDetectLength = 100;

if (self.backgroundColor == nil)
{
Expand Down Expand Up @@ -1042,7 +1041,8 @@ - (void)recomputeLinksIfNeeded
{
return;
}
BOOL sync = length <= self.maxSyncDetectLength;
M80SyncLinkChecker checker = M80AttributedLabelConfig.shared.checker;
BOOL sync = checker ? checker(text) : YES;
[self computeLink:text
sync:sync];
}
Expand Down Expand Up @@ -1189,11 +1189,4 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
}
}

#pragma mark - 设置自定义的连接检测block
+ (void)setCustomDetectMethod:(M80CustomDetectLinkBlock)block
{
[M80AttributedLabelURL setCustomDetectMethod:block];
}


@end
25 changes: 25 additions & 0 deletions M80AttributedLabel/M80AttributedLabelConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// M80AttributedLabelConfig.h
// M80AttributedLabel
//
// Created by amao on 2019/2/14.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

typedef NSArray * _Nullable (^M80LinkDetector)(NSString * _Nullable text);
typedef BOOL (^M80SyncLinkChecker)(NSString * _Nullable text);


@interface M80AttributedLabelConfig : NSObject
@property (nonatomic,copy,nullable) M80LinkDetector detector;

@property (nonatomic,copy,nullable) M80SyncLinkChecker checker;

+ (instancetype)shared;

@end

NS_ASSUME_NONNULL_END
20 changes: 20 additions & 0 deletions M80AttributedLabel/M80AttributedLabelConfig.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// M80AttributedLabelConfig.m
// M80AttributedLabel
//
// Created by amao on 2019/2/14.
//

#import "M80AttributedLabelConfig.h"

@implementation M80AttributedLabelConfig
+ (instancetype)shared
{
static M80AttributedLabelConfig *instance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [M80AttributedLabelConfig new];
});
return instance;
}
@end
2 changes: 0 additions & 2 deletions M80AttributedLabel/M80AttributedLabelURL.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ NS_ASSUME_NONNULL_BEGIN


+ (nullable NSArray *)detectLinks:(nullable NSString *)plainText;

+ (void)setCustomDetectMethod:(nullable M80CustomDetectLinkBlock)block;
@end


Expand Down
13 changes: 4 additions & 9 deletions M80AttributedLabel/M80AttributedLabelURL.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
//

#import "M80AttributedLabelURL.h"
#import "M80AttributedLabelConfig.h"

static M80CustomDetectLinkBlock customDetectBlock = nil;

@implementation M80AttributedLabelURL

Expand All @@ -27,9 +27,10 @@ + (M80AttributedLabelURL *)urlWithLinkData:(id)linkData

+ (NSArray *)detectLinks:(NSString *)plainText
{
if (customDetectBlock)
M80LinkDetector detector = M80AttributedLabelConfig.shared.detector;
if (detector)
{
return customDetectBlock(plainText);
return detector(plainText);
}
else
{
Expand Down Expand Up @@ -72,10 +73,4 @@ + (NSDataDetector *)linkDetector
return detector;
}


+ (void)setCustomDetectMethod:(M80CustomDetectLinkBlock)block
{
customDetectBlock = [block copy];
}

@end
37 changes: 4 additions & 33 deletions OCDemo/OCDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@
E4A331021DAE054900B59A16 /* Sources */,
E4A331031DAE054900B59A16 /* Frameworks */,
E4A331041DAE054900B59A16 /* Resources */,
CEAE485A7D846249EDC75032 /* [CP] Embed Pods Frameworks */,
11EEBB09F9C6ABAFF404129A /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -272,49 +270,22 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
11EEBB09F9C6ABAFF404129A /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-OCDemo/Pods-OCDemo-resources.sh\"\n";
showEnvVarsInLog = 0;
};
B256097B57CCF5BE559E55FE /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-OCDemo-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
CEAE485A7D846249EDC75032 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-OCDemo/Pods-OCDemo-frameworks.sh\"\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand Down
6 changes: 3 additions & 3 deletions OCDemo/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- M80AttributedLabel (1.6.2)
- M80AttributedLabel (1.8.1)

DEPENDENCIES:
- M80AttributedLabel (from `../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
M80AttributedLabel: 1bcddc0acb6097991bb41fe17fbf947d128836d6
M80AttributedLabel: 5fc22e2a4a9ed7625d69ad5520804c4e26926485

PODFILE CHECKSUM: c204fac8364187b2bd67bb03850fcbcaad8bfd33

COCOAPODS: 1.1.1
COCOAPODS: 1.5.3

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions OCDemo/Pods/Local Podspecs/M80AttributedLabel.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions OCDemo/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6046ec7

Please sign in to comment.