-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
该bug曾经导致NSParagraphStyle相关的功能无法通过模板进行覆盖,只要在模板和text里同时定义了NSParagraphStyle相关的属性,模板里的NSParagraphStyle属性就会被覆盖
- Loading branch information
Matt Cai
committed
Nov 1, 2018
1 parent
63d380e
commit 01bc3e9
Showing
4 changed files
with
148 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// NUDParagraphStyle.h | ||
// textExample | ||
// | ||
// Created by Ruite Chen on 2018/11/1. | ||
// Copyright © 2018 com.CAI. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface NUDParagraphStyle : NSMutableParagraphStyle | ||
|
||
@end | ||
|
||
@interface NSMutableParagraphStyle (NUDParagraphStyle) | ||
|
||
- (void)nud_mergeParagraphStyle:(NSMutableParagraphStyle *)paragraphStyle; | ||
|
||
@end | ||
|
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,98 @@ | ||
// | ||
// NUDParagraphStyle.m | ||
// textExample | ||
// | ||
// Created by Ruite Chen on 2018/11/1. | ||
// Copyright © 2018 com.CAI. All rights reserved. | ||
// | ||
|
||
#import "NUDParagraphStyle.h" | ||
#import <objc/runtime.h> | ||
|
||
@interface NUDParagraphStyle () | ||
- (void)addTag:(NSString *)key; | ||
- (NSArray<NSString *> *)keyTags; | ||
@end | ||
|
||
@implementation NUDParagraphStyle | ||
- (void)setLineSpacing:(CGFloat)lineSpacing { | ||
[super setLineSpacing:lineSpacing]; | ||
[self addTag:@"lineSpacing"]; | ||
} | ||
- (void)setParagraphSpacing:(CGFloat)paragraphSpacing { | ||
[super setParagraphSpacing:paragraphSpacing]; | ||
[self addTag:@"paragraphSpacing"]; | ||
} | ||
- (void)setParagraphSpacingBefore:(CGFloat)paragraphSpacingBefore { | ||
[super setParagraphSpacingBefore:paragraphSpacingBefore]; | ||
[self addTag:@"paragraphSpacingBefore"]; | ||
} | ||
- (void)setAlignment:(NSTextAlignment)alignment { | ||
[super setAlignment:alignment]; | ||
[self addTag:@"alignment"]; | ||
} | ||
- (void)setFirstLineHeadIndent:(CGFloat)firstLineHeadIndent { | ||
[super setFirstLineHeadIndent:firstLineHeadIndent]; | ||
[self addTag:@"firstLineHeadIndent"]; | ||
} | ||
- (void)setHeadIndent:(CGFloat)headIndent { | ||
[super setHeadIndent:headIndent]; | ||
[self addTag:@"headIndent"]; | ||
} | ||
- (void)setTailIndent:(CGFloat)tailIndent { | ||
[super setTailIndent:tailIndent]; | ||
[self addTag:@"tailIndent"]; | ||
} | ||
- (void)setLineBreakMode:(NSLineBreakMode)lineBreakMode { | ||
[super setLineBreakMode:lineBreakMode]; | ||
[self addTag:@"lineBreakMode"]; | ||
} | ||
- (void)setMaximumLineHeight:(CGFloat)maximumLineHeight { | ||
[super setMaximumLineHeight:maximumLineHeight]; | ||
[self addTag:@"maximumLineHeight"]; | ||
} | ||
- (void)setMinimumLineHeight:(CGFloat)minimumLineHeight { | ||
[super setMinimumLineHeight:minimumLineHeight]; | ||
[self addTag:@"minimumLineHeight"]; | ||
} | ||
- (void)setBaseWritingDirection:(NSWritingDirection)baseWritingDirection { | ||
[super setBaseWritingDirection:baseWritingDirection]; | ||
[self addTag:@"baseWritingDirection"]; | ||
} | ||
- (void)setLineHeightMultiple:(CGFloat)lineHeightMultiple { | ||
[super setLineHeightMultiple:lineHeightMultiple]; | ||
[self addTag:@"lineHeightMultiple"]; | ||
} | ||
- (void)setHyphenationFactor:(float)hyphenationFactor { | ||
[super setHyphenationFactor:hyphenationFactor]; | ||
[self addTag:@"hyphenationFactor"]; | ||
} | ||
|
||
- (void)addTag:(NSString *)key { | ||
NSMutableArray<NSString *> *keys = objc_getAssociatedObject(self, "com.NudeIn.NUDParagraphStyle.keys"); | ||
if (!keys) { | ||
keys = [NSMutableArray new]; | ||
objc_setAssociatedObject(self, "com.NudeIn.NUDParagraphStyle.keys", keys, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | ||
} | ||
[keys addObject:key]; | ||
} | ||
- (NSArray<NSString *> *)keyTags { | ||
NSArray<NSString *> *keys = objc_getAssociatedObject(self, "com.NudeIn.NUDParagraphStyle.keys"); | ||
return keys; | ||
} | ||
@end | ||
|
||
@implementation NSMutableParagraphStyle (NUDParagraphStyle) | ||
|
||
- (void)nud_mergeParagraphStyle:(NSMutableParagraphStyle *)paragraphStyle { | ||
if ([paragraphStyle isKindOfClass:[NUDParagraphStyle class]]) { | ||
for (NSString *key in ((NUDParagraphStyle *)paragraphStyle).keyTags) { | ||
[self setValue:[paragraphStyle valueForKey:key] forKey:key]; | ||
} | ||
}else { | ||
@throw [NSException exceptionWithName:NSInternalInconsistencyException | ||
reason:@"NSMutableParagraphStyle is not a NUDParagraphStyle" userInfo:nil]; | ||
} | ||
} | ||
|
||
@end |
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