Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

If the numberOfLines is 1, sizeThatFits returns the full required wid…

…th of the text
  • Loading branch information...
commit 963925340beee9021ec50ad1783da4aa1a940a51 1 parent 6c8fa60
@PeteC PeteC authored
Showing with 8 additions and 3 deletions.
  1. +8 −3 TTTAttributedLabel.m
View
11 TTTAttributedLabel.m
@@ -528,9 +528,14 @@ - (CGSize)sizeThatFits:(CGSize)size {
}
CFRange rangeToSize = CFRangeMake(0, [self.attributedText length]);
+ CGSize constraints = CGSizeMake(size.width, CGFLOAT_MAX);
- // If the line count of the label isn't 0, limit the range to size to the number of lines that have been set
- if (self.numberOfLines > 0) {
+ if (self.numberOfLines == 1) {
+ // If there is one line, the size that fits is the full width of the line
+ constraints = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);
+ }
+ else if (self.numberOfLines > 0) {
+ // If the line count of the label more than 1, limit the range to size to the number of lines that have been set
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, CGRectMake(0, 0, self.bounds.size.width, CGFLOAT_MAX));
@@ -549,7 +554,7 @@ - (CGSize)sizeThatFits:(CGSize)size {
CFRelease(path);
}
- CGSize suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(self.framesetter, rangeToSize, NULL, CGSizeMake(size.width, CGFLOAT_MAX), NULL);
+ CGSize suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(self.framesetter, rangeToSize, NULL, constraints, NULL);
return CGSizeMake(ceilf(suggestedSize.width), ceilf(suggestedSize.height));
}
Please sign in to comment.
Something went wrong with that request. Please try again.