From 79394cd907238d0c54507b414a9b6440d9201a88 Mon Sep 17 00:00:00 2001 From: aiXing <862099730@qq.com> Date: Mon, 27 Jun 2016 18:56:11 +0800 Subject: [PATCH] bug fixs. --- AXAttributedLabel.podspec | 4 +- .../AXAttributedLabel/AXAttributedLabel.m | 64 +++++++------------ 2 files changed, 25 insertions(+), 43 deletions(-) diff --git a/AXAttributedLabel.podspec b/AXAttributedLabel.podspec index c9bae12..fd030d4 100644 --- a/AXAttributedLabel.podspec +++ b/AXAttributedLabel.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |s| s.name = "AXAttributedLabel" -s.version = "0.2.7" +s.version = "0.2.8" s.summary = "`AXAttributedLabel` is an iOS customizable attributed label that displays attributed text." s.description = <<-DESC @@ -21,7 +21,7 @@ s.platform = :ios, "7.0" # s.ios.deployment_target = “7.0” # s.osx.deployment_target = "10.7" # s.watchos.deployment_target = "2.0" -s.source = { :git => "https://github.com/devedbox/AXAttributedLabel.git", :tag => "0.2.7" } +s.source = { :git => "https://github.com/devedbox/AXAttributedLabel.git", :tag => "0.2.8" } s.source_files = "AXAttributedLabel/AXAttributedLabel/*.{h,m}" #s.exclude_files = "Classes/Exclude" # s.public_header_files = "Classes/**/*.h" diff --git a/AXAttributedLabel/AXAttributedLabel/AXAttributedLabel.m b/AXAttributedLabel/AXAttributedLabel/AXAttributedLabel.m index c40e37b..e81a2df 100644 --- a/AXAttributedLabel/AXAttributedLabel/AXAttributedLabel.m +++ b/AXAttributedLabel/AXAttributedLabel/AXAttributedLabel.m @@ -196,7 +196,7 @@ - (void)initializer { } } // Set up layout manager. - self.layoutManager.allowsNonContiguousLayout = NO; + self.layoutManager.allowsNonContiguousLayout = YES; self.layoutManager.delegate = self; // Set up text container. self.lineBreakMode = NSLineBreakByTruncatingTail; @@ -394,17 +394,9 @@ - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event [super touchesCancelled:touches withEvent:event]; } -- (void)didMoveToSuperview { - [super didMoveToSuperview]; - if (self.translatesAutoresizingMaskIntoConstraints == NO) { - [self invalidateIntrinsicContentSize]; - } -} - - (CGSize)sizeThatFits:(CGSize)size { CGSize susize = [super sizeThatFits:size]; susize.width = self.frame.size.width; - [self.layoutManager ensureLayoutForTextContainer:self.textContainer]; susize.height = ceil([self.layoutManager usedRectForTextContainer:self.textContainer].size.height)+self.textContainerInset.top+self.textContainerInset.bottom; return susize; } @@ -423,33 +415,28 @@ - (CGSize)intrinsicContentSize { - (void)layoutSubviews { [super layoutSubviews]; // Layout the text container view. - if (_textContainerView) { - CGRect rect_container = _textContainerView.frame; - [self.layoutManager ensureLayoutForTextContainer:self.textContainer]; - CGSize usedSize = [self.layoutManager usedRectForTextContainer:self.textContainer].size; - rect_container.size = CGSizeMake(ceil(usedSize.width)+self.textContainerInset.left+self.textContainerInset.right, ceil(usedSize.height+self.textContainerInset.top+self.textContainerInset.bottom)); - rect_container.size.width = MAX(rect_container.size.width, CGRectGetWidth(self.frame)); - if (CGRectGetHeight(rect_container)>=CGRectGetHeight(self.frame)) { - // Use AXAttributedLabelVerticalAlignmentTop. - rect_container.origin.y = .0; - rect_container.size.height = CGRectGetHeight(self.frame); - } else { - // Use the vertical alignment. - switch (_verticalAlignment) { - case AXAttributedLabelVerticalAlignmentTop: - rect_container.origin.y = .0; - break; - case AXAttributedLabelVerticalAlignmentBottom: - rect_container.origin.y = CGRectGetHeight(self.frame) - CGRectGetHeight(rect_container); - break; - case AXAttributedLabelVerticalAlignmentCenter: - default: - rect_container.origin.y = CGRectGetHeight(self.frame)*.5-CGRectGetHeight(rect_container)*.5; - break; - } + CGRect rect_container = _textContainerView.frame; + rect_container.size.width = MAX(rect_container.size.width, CGRectGetWidth(self.frame)); + if (CGRectGetHeight(rect_container)>=CGRectGetHeight(self.frame)) { + // Use AXAttributedLabelVerticalAlignmentTop. + rect_container.origin.y = .0; + rect_container.size.height = CGRectGetHeight(self.frame); + } else { + // Use the vertical alignment. + switch (_verticalAlignment) { + case AXAttributedLabelVerticalAlignmentTop: + rect_container.origin.y = .0; + break; + case AXAttributedLabelVerticalAlignmentBottom: + rect_container.origin.y = CGRectGetHeight(self.frame) - CGRectGetHeight(rect_container); + break; + case AXAttributedLabelVerticalAlignmentCenter: + default: + rect_container.origin.y = CGRectGetHeight(self.frame)*.5-CGRectGetHeight(rect_container)*.5; + break; } - _textContainerView.frame = rect_container; } + _textContainerView.frame = rect_container; } #pragma mark - Getters - (NSString *)text { @@ -557,8 +544,6 @@ - (void)setAttributedText:(NSAttributedString *)attributedText { } [super setAttributedText:attributedText]; _shouldUpdateBoundingSize = YES; - [self.layoutManager ensureLayoutForTextContainer:self.textContainer]; - [self invalidateIntrinsicContentSize]; } - (void)setFont:(UIFont *)font { @@ -590,7 +575,6 @@ - (void)setTextContainerInset:(UIEdgeInsets)textContainerInset { return; } [super setTextContainerInset:textContainerInset]; - [self invalidateIntrinsicContentSize]; _shouldUpdateBoundingSize = YES; } @@ -664,18 +648,15 @@ - (void)setShouldInteractWithAttachments:(BOOL)shouldInteractWithAttachments { - (void)setLineBreakMode:(NSLineBreakMode)lineBreakMode { self.textContainer.lineBreakMode = lineBreakMode; - [self.layoutManager ensureLayoutForTextContainer:self.textContainer]; } - (void)setNumberOfLines:(NSUInteger)numberOfLines { self.textContainer.maximumNumberOfLines = numberOfLines; - [self.layoutManager ensureLayoutForTextContainer:self.textContainer]; } - (void)setExclusionPaths:(NSArray *)exclusionPaths { self.textContainer.exclusionPaths = exclusionPaths; _shouldUpdateBoundingSize = YES; - [self.layoutManager ensureLayoutForTextContainer:self.textContainer]; } - (void)setExclusionViews:(NSArray *)exclusionViews { @@ -1108,7 +1089,8 @@ - (void)layoutManager:(NSLayoutManager *)layoutManager didCompleteLayoutForTextC [self invalidateIntrinsicContentSize]; } - (void)layoutManager:(NSLayoutManager *)layoutManager textContainer:(NSTextContainer *)textContainer didChangeGeometryFromSize:(CGSize)oldSize { - [self invalidateIntrinsicContentSize]; + [self.textContainer setSize:self.bounds.size]; + [self.layoutManager ensureLayoutForTextContainer:self.textContainer]; } @end