Skip to content

Commit 6046ec7

Browse files
author
amao
committed
1.9.0 添加配置项
1 parent 58895dd commit 6046ec7

33 files changed

+876
-625
lines changed

M80AttributedLabel.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'M80AttributedLabel'
3-
s.version = '1.8.1'
3+
s.version = '1.9.0'
44
s.authors = {'Xiang Wangfeng' => 'xiangwangfeng@gmail.com'}
55
s.homepage = 'https://github.com/xiangwangfeng/M80AttributedLabel/'
66
s.summary = 'Another attributed label using CoreText'

M80AttributedLabel/M80AttributedLabel.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#import "M80AttributedLabelDefines.h"
1010
#import "NSMutableAttributedString+M80.h"
11+
#import "M80AttributedLabelConfig.h"
12+
1113

1214
NS_ASSUME_NONNULL_BEGIN
1315

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

3737

3838
//添加文本
@@ -72,9 +72,6 @@ NS_ASSUME_NONNULL_BEGIN
7272
//大小
7373
- (CGSize)sizeThatFits:(CGSize)size;
7474

75-
//设置全局的自定义Link检测Block(详见M80AttributedLabelURL)
76-
+ (void)setCustomDetectMethod:(nullable M80CustomDetectLinkBlock)block;
77-
7875
@end
7976

8077
NS_ASSUME_NONNULL_END

M80AttributedLabel/M80AttributedLabel.m

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ - (void)commonInit
8686
_autoDetectLinks = YES;
8787
_lineSpacing = 0.0;
8888
_paragraphSpacing = 0.0;
89-
_maxSyncDetectLength = 100;
9089

9190
if (self.backgroundColor == nil)
9291
{
@@ -1042,7 +1041,8 @@ - (void)recomputeLinksIfNeeded
10421041
{
10431042
return;
10441043
}
1045-
BOOL sync = length <= self.maxSyncDetectLength;
1044+
M80SyncLinkChecker checker = M80AttributedLabelConfig.shared.checker;
1045+
BOOL sync = checker ? checker(text) : YES;
10461046
[self computeLink:text
10471047
sync:sync];
10481048
}
@@ -1189,11 +1189,4 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
11891189
}
11901190
}
11911191

1192-
#pragma mark - 设置自定义的连接检测block
1193-
+ (void)setCustomDetectMethod:(M80CustomDetectLinkBlock)block
1194-
{
1195-
[M80AttributedLabelURL setCustomDetectMethod:block];
1196-
}
1197-
1198-
11991192
@end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// M80AttributedLabelConfig.h
3+
// M80AttributedLabel
4+
//
5+
// Created by amao on 2019/2/14.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
10+
NS_ASSUME_NONNULL_BEGIN
11+
12+
typedef NSArray * _Nullable (^M80LinkDetector)(NSString * _Nullable text);
13+
typedef BOOL (^M80SyncLinkChecker)(NSString * _Nullable text);
14+
15+
16+
@interface M80AttributedLabelConfig : NSObject
17+
@property (nonatomic,copy,nullable) M80LinkDetector detector;
18+
19+
@property (nonatomic,copy,nullable) M80SyncLinkChecker checker;
20+
21+
+ (instancetype)shared;
22+
23+
@end
24+
25+
NS_ASSUME_NONNULL_END
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// M80AttributedLabelConfig.m
3+
// M80AttributedLabel
4+
//
5+
// Created by amao on 2019/2/14.
6+
//
7+
8+
#import "M80AttributedLabelConfig.h"
9+
10+
@implementation M80AttributedLabelConfig
11+
+ (instancetype)shared
12+
{
13+
static M80AttributedLabelConfig *instance = nil;
14+
static dispatch_once_t onceToken;
15+
dispatch_once(&onceToken, ^{
16+
instance = [M80AttributedLabelConfig new];
17+
});
18+
return instance;
19+
}
20+
@end

M80AttributedLabel/M80AttributedLabelURL.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ NS_ASSUME_NONNULL_BEGIN
2222

2323

2424
+ (nullable NSArray *)detectLinks:(nullable NSString *)plainText;
25-
26-
+ (void)setCustomDetectMethod:(nullable M80CustomDetectLinkBlock)block;
2725
@end
2826

2927

M80AttributedLabel/M80AttributedLabelURL.m

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
//
88

99
#import "M80AttributedLabelURL.h"
10+
#import "M80AttributedLabelConfig.h"
1011

11-
static M80CustomDetectLinkBlock customDetectBlock = nil;
1212

1313
@implementation M80AttributedLabelURL
1414

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

2828
+ (NSArray *)detectLinks:(NSString *)plainText
2929
{
30-
if (customDetectBlock)
30+
M80LinkDetector detector = M80AttributedLabelConfig.shared.detector;
31+
if (detector)
3132
{
32-
return customDetectBlock(plainText);
33+
return detector(plainText);
3334
}
3435
else
3536
{
@@ -72,10 +73,4 @@ + (NSDataDetector *)linkDetector
7273
return detector;
7374
}
7475

75-
76-
+ (void)setCustomDetectMethod:(M80CustomDetectLinkBlock)block
77-
{
78-
customDetectBlock = [block copy];
79-
}
80-
8176
@end

OCDemo/OCDemo.xcodeproj/project.pbxproj

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,6 @@
206206
E4A331021DAE054900B59A16 /* Sources */,
207207
E4A331031DAE054900B59A16 /* Frameworks */,
208208
E4A331041DAE054900B59A16 /* Resources */,
209-
CEAE485A7D846249EDC75032 /* [CP] Embed Pods Frameworks */,
210-
11EEBB09F9C6ABAFF404129A /* [CP] Copy Pods Resources */,
211209
);
212210
buildRules = (
213211
);
@@ -272,49 +270,22 @@
272270
/* End PBXResourcesBuildPhase section */
273271

274272
/* Begin PBXShellScriptBuildPhase section */
275-
11EEBB09F9C6ABAFF404129A /* [CP] Copy Pods Resources */ = {
276-
isa = PBXShellScriptBuildPhase;
277-
buildActionMask = 2147483647;
278-
files = (
279-
);
280-
inputPaths = (
281-
);
282-
name = "[CP] Copy Pods Resources";
283-
outputPaths = (
284-
);
285-
runOnlyForDeploymentPostprocessing = 0;
286-
shellPath = /bin/sh;
287-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-OCDemo/Pods-OCDemo-resources.sh\"\n";
288-
showEnvVarsInLog = 0;
289-
};
290273
B256097B57CCF5BE559E55FE /* [CP] Check Pods Manifest.lock */ = {
291274
isa = PBXShellScriptBuildPhase;
292275
buildActionMask = 2147483647;
293276
files = (
294277
);
295278
inputPaths = (
279+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
280+
"${PODS_ROOT}/Manifest.lock",
296281
);
297282
name = "[CP] Check Pods Manifest.lock";
298283
outputPaths = (
284+
"$(DERIVED_FILE_DIR)/Pods-OCDemo-checkManifestLockResult.txt",
299285
);
300286
runOnlyForDeploymentPostprocessing = 0;
301287
shellPath = /bin/sh;
302-
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";
303-
showEnvVarsInLog = 0;
304-
};
305-
CEAE485A7D846249EDC75032 /* [CP] Embed Pods Frameworks */ = {
306-
isa = PBXShellScriptBuildPhase;
307-
buildActionMask = 2147483647;
308-
files = (
309-
);
310-
inputPaths = (
311-
);
312-
name = "[CP] Embed Pods Frameworks";
313-
outputPaths = (
314-
);
315-
runOnlyForDeploymentPostprocessing = 0;
316-
shellPath = /bin/sh;
317-
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-OCDemo/Pods-OCDemo-frameworks.sh\"\n";
288+
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";
318289
showEnvVarsInLog = 0;
319290
};
320291
/* End PBXShellScriptBuildPhase section */

OCDemo/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- M80AttributedLabel (1.6.2)
2+
- M80AttributedLabel (1.8.1)
33

44
DEPENDENCIES:
55
- M80AttributedLabel (from `../`)
@@ -9,8 +9,8 @@ EXTERNAL SOURCES:
99
:path: "../"
1010

1111
SPEC CHECKSUMS:
12-
M80AttributedLabel: 1bcddc0acb6097991bb41fe17fbf947d128836d6
12+
M80AttributedLabel: 5fc22e2a4a9ed7625d69ad5520804c4e26926485
1313

1414
PODFILE CHECKSUM: c204fac8364187b2bd67bb03850fcbcaad8bfd33
1515

16-
COCOAPODS: 1.1.1
16+
COCOAPODS: 1.5.3

OCDemo/Pods/Headers/Private/M80AttributedLabel/M80AttributedLabelConfig.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)