Skip to content

Commit

Permalink
bug fixs.
Browse files Browse the repository at this point in the history
  • Loading branch information
devedbox committed Jun 27, 2016
1 parent 3c1a769 commit 79394cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 43 deletions.
4 changes: 2 additions & 2 deletions AXAttributedLabel.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
64 changes: 23 additions & 41 deletions AXAttributedLabel/AXAttributedLabel/AXAttributedLabel.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -394,17 +394,9 @@ - (void)touchesCancelled:(NSSet<UITouch *> *)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;
}
Expand All @@ -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 {
Expand Down Expand Up @@ -557,8 +544,6 @@ - (void)setAttributedText:(NSAttributedString *)attributedText {
}
[super setAttributedText:attributedText];
_shouldUpdateBoundingSize = YES;
[self.layoutManager ensureLayoutForTextContainer:self.textContainer];
[self invalidateIntrinsicContentSize];
}

- (void)setFont:(UIFont *)font {
Expand Down Expand Up @@ -590,7 +575,6 @@ - (void)setTextContainerInset:(UIEdgeInsets)textContainerInset {
return;
}
[super setTextContainerInset:textContainerInset];
[self invalidateIntrinsicContentSize];
_shouldUpdateBoundingSize = YES;
}

Expand Down Expand Up @@ -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<UIBezierPath *> *)exclusionPaths {
self.textContainer.exclusionPaths = exclusionPaths;
_shouldUpdateBoundingSize = YES;
[self.layoutManager ensureLayoutForTextContainer:self.textContainer];
}

- (void)setExclusionViews:(NSArray<UIView *> *)exclusionViews {
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 79394cd

Please sign in to comment.