Skip to content

Commit 659cfc6

Browse files
author
amao
committed
添加 set property 更新 text frame 的操作
1 parent ff8d90c commit 659cfc6

6 files changed

Lines changed: 149 additions & 32 deletions

File tree

M80AttributedLabel/M80AttributedLabel.m

Lines changed: 84 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ - (void)resetFont
137137
}
138138

139139
#pragma mark - 属性设置
140-
//保证正常绘制,如果传入nil就直接不处理
141140
- (void)setFont:(UIFont *)font
142141
{
143142
if (font && _font != font)
@@ -167,10 +166,9 @@ - (void)setTextColor:(UIColor *)textColor
167166

168167
- (void)setHighlightColor:(UIColor *)highlightColor
169168
{
170-
if (highlightColor && _highlightColor != highlightColor)
169+
if (_highlightColor != highlightColor)
171170
{
172171
_highlightColor = highlightColor;
173-
174172
[self resetTextFrame];
175173
}
176174
}
@@ -184,51 +182,115 @@ - (void)setLinkColor:(UIColor *)linkColor
184182
}
185183
}
186184

187-
- (void)setFrame:(CGRect)frame
185+
- (void)setShadowColor:(UIColor *)shadowColor
188186
{
189-
CGRect oldRect = self.bounds;
190-
[super setFrame:frame];
191-
192-
if (!CGRectEqualToRect(self.bounds, oldRect))
187+
if (_shadowColor != shadowColor)
193188
{
189+
_shadowColor = shadowColor;
194190
[self resetTextFrame];
195191
}
196192
}
197193

198-
- (void)setBounds:(CGRect)bounds
194+
- (void)setShadowOffset:(CGSize)shadowOffset
199195
{
200-
CGRect oldRect = self.bounds;
201-
[super setBounds:bounds];
202-
203-
if (!CGRectEqualToRect(self.bounds, oldRect))
196+
if (!CGSizeEqualToSize(_shadowOffset, shadowOffset))
204197
{
198+
_shadowOffset = shadowOffset;
205199
[self resetTextFrame];
206200
}
207201
}
208202

209-
- (void)setShadowColor:(UIColor *)shadowColor
203+
- (void)setShadowBlur:(CGFloat)shadowBlur
210204
{
211-
if (_shadowColor != shadowColor)
205+
if (_shadowBlur != shadowBlur)
212206
{
213-
_shadowColor = shadowColor;
207+
_shadowBlur = shadowBlur;
214208
[self resetTextFrame];
215209
}
216210
}
217211

218-
- (void)setShadowOffset:(CGSize)shadowOffset
212+
- (void)setUnderLineForLink:(BOOL)underLineForLink
219213
{
220-
if (!CGSizeEqualToSize(_shadowOffset, shadowOffset))
214+
if (_underLineForLink != underLineForLink)
221215
{
222-
_shadowOffset = shadowOffset;
216+
_underLineForLink = underLineForLink;
223217
[self resetTextFrame];
224218
}
225219
}
226220

227-
- (void)setShadowBlur:(CGFloat)shadowBlur
221+
- (void)setAutoDetectLinks:(BOOL)autoDetectLinks
228222
{
229-
if (_shadowBlur != shadowBlur)
223+
if (_autoDetectLinks != autoDetectLinks)
224+
{
225+
_autoDetectLinks = autoDetectLinks;
226+
[self resetTextFrame];
227+
}
228+
}
229+
230+
- (void)setNumberOfLines:(NSInteger)numberOfLines
231+
{
232+
if (_numberOfLines != numberOfLines)
233+
{
234+
_numberOfLines = numberOfLines;
235+
[self resetTextFrame];
236+
}
237+
}
238+
239+
- (void)setTextAlignment:(CTTextAlignment)textAlignment
240+
{
241+
if (_textAlignment != textAlignment)
242+
{
243+
_textAlignment = textAlignment;
244+
[self resetTextFrame];
245+
}
246+
}
247+
248+
- (void)setLineBreakMode:(CTLineBreakMode)lineBreakMode
249+
{
250+
if (_lineBreakMode != lineBreakMode)
251+
{
252+
_lineBreakMode = lineBreakMode;
253+
[self resetTextFrame];
254+
}
255+
}
256+
257+
- (void)setLineSpacing:(CGFloat)lineSpacing
258+
{
259+
if (_lineSpacing != lineSpacing)
260+
{
261+
_lineSpacing = lineSpacing;
262+
[self resetTextFrame];
263+
}
264+
}
265+
266+
- (void)setParagraphSpacing:(CGFloat)paragraphSpacing
267+
{
268+
if (_paragraphSpacing != paragraphSpacing)
269+
{
270+
_paragraphSpacing = paragraphSpacing;
271+
[self resetTextFrame];
272+
}
273+
}
274+
275+
#pragma mark - frame
276+
- (void)setFrame:(CGRect)frame
277+
{
278+
CGRect oldRect = self.bounds;
279+
[super setFrame:frame];
280+
281+
if (!CGRectEqualToRect(self.bounds, oldRect))
282+
{
283+
[self resetTextFrame];
284+
}
285+
}
286+
287+
- (void)setBounds:(CGRect)bounds
288+
{
289+
CGRect oldRect = self.bounds;
290+
[super setBounds:bounds];
291+
292+
if (!CGRectEqualToRect(self.bounds, oldRect))
230293
{
231-
_shadowBlur = shadowBlur;
232294
[self resetTextFrame];
233295
}
234296
}

M80AttributedLabel/NSMutableAttributedString+M80.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ - (void)m80_setTextColor:(UIColor*)color
1717

1818
- (void)m80_setTextColor:(UIColor*)color range:(NSRange)range
1919
{
20+
[self removeAttribute:(NSString *)kCTForegroundColorAttributeName range:range];
2021
if (color.CGColor)
2122
{
22-
[self removeAttribute:(NSString *)kCTForegroundColorAttributeName range:range];
23+
2324

2425
[self addAttribute:(NSString *)kCTForegroundColorAttributeName
2526
value:(id)color.CGColor
2627
range:range];
2728
}
28-
2929
}
3030

3131

OCDemo/OCDemo.xcodeproj/project.pbxproj

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@
224224
E4A330FE1DAE054900B59A16 /* Project object */ = {
225225
isa = PBXProject;
226226
attributes = {
227-
LastUpgradeCheck = 0810;
227+
LastUpgradeCheck = 1000;
228228
ORGANIZATIONNAME = amao;
229229
TargetAttributes = {
230230
E4A331051DAE054900B59A16 = {
@@ -372,15 +372,23 @@
372372
CLANG_CXX_LIBRARY = "libc++";
373373
CLANG_ENABLE_MODULES = YES;
374374
CLANG_ENABLE_OBJC_ARC = YES;
375+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
375376
CLANG_WARN_BOOL_CONVERSION = YES;
377+
CLANG_WARN_COMMA = YES;
376378
CLANG_WARN_CONSTANT_CONVERSION = YES;
379+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
377380
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
378381
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
379382
CLANG_WARN_EMPTY_BODY = YES;
380383
CLANG_WARN_ENUM_CONVERSION = YES;
381384
CLANG_WARN_INFINITE_RECURSION = YES;
382385
CLANG_WARN_INT_CONVERSION = YES;
386+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
387+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
388+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
383389
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
390+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
391+
CLANG_WARN_STRICT_PROTOTYPES = YES;
384392
CLANG_WARN_SUSPICIOUS_MOVE = YES;
385393
CLANG_WARN_SUSPICIOUS_MOVES = YES;
386394
CLANG_WARN_UNREACHABLE_CODE = YES;
@@ -420,15 +428,23 @@
420428
CLANG_CXX_LIBRARY = "libc++";
421429
CLANG_ENABLE_MODULES = YES;
422430
CLANG_ENABLE_OBJC_ARC = YES;
431+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
423432
CLANG_WARN_BOOL_CONVERSION = YES;
433+
CLANG_WARN_COMMA = YES;
424434
CLANG_WARN_CONSTANT_CONVERSION = YES;
435+
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
425436
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
426437
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
427438
CLANG_WARN_EMPTY_BODY = YES;
428439
CLANG_WARN_ENUM_CONVERSION = YES;
429440
CLANG_WARN_INFINITE_RECURSION = YES;
430441
CLANG_WARN_INT_CONVERSION = YES;
442+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
443+
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
444+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
431445
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
446+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
447+
CLANG_WARN_STRICT_PROTOTYPES = YES;
432448
CLANG_WARN_SUSPICIOUS_MOVE = YES;
433449
CLANG_WARN_SUSPICIOUS_MOVES = YES;
434450
CLANG_WARN_UNREACHABLE_CODE = YES;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

OCDemo/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 30 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

0 commit comments

Comments
 (0)