Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: ios/chrome/browser/ui/util/CRUILabel+AttributeUtils.mm

Issue 2828743002: LabelObserver is no longer retained by the label (Closed)
Patch Set: Address comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ios/chrome/browser/ui/util/CRUILabel+AttributeUtils.h" 5 #include "ios/chrome/browser/ui/util/CRUILabel+AttributeUtils.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 8
9 #import "base/ios/weak_nsobject.h" 9 #import "base/ios/weak_nsobject.h"
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 style = [NSParagraphStyle defaultParagraphStyle]; 67 style = [NSParagraphStyle defaultParagraphStyle];
68 base::scoped_nsobject<NSMutableParagraphStyle> newStyle([style mutableCopy]); 68 base::scoped_nsobject<NSMutableParagraphStyle> newStyle([style mutableCopy]);
69 [newStyle setMinimumLineHeight:lineHeight]; 69 [newStyle setMinimumLineHeight:lineHeight];
70 [newStyle setMaximumLineHeight:lineHeight]; 70 [newStyle setMaximumLineHeight:lineHeight];
71 [newString addAttribute:NSParagraphStyleAttributeName 71 [newString addAttribute:NSParagraphStyleAttributeName
72 value:newStyle 72 value:newStyle
73 range:NSMakeRange(0, [newString length])]; 73 range:NSMakeRange(0, [newString length])];
74 self.attributedText = newString; 74 self.attributedText = newString;
75 } 75 }
76 76
77 - (void)cr_adjustLineHeightForMaximimumLines:(NSUInteger)maximumLines {
78 CGSize labelSize = self.bounds.size;
79 CGFloat lineHeight = self.cr_lineHeight;
80 CGFloat numberOfLines = floorf(labelSize.height / lineHeight);
81 CGSize maxSize = CGSizeMake(labelSize.width, CGFLOAT_MAX);
82 CGSize textSize = [self sizeThatFits:maxSize];
83
84 // |textSize.height| should be a multiple of |lineHeight|. If this is not the
85 // case, then it is safer to fit one more line to ensure that the text of the
86 // label is not cropped.
87 CGFloat requiredNumberOfLines = ceilf(textSize.height / lineHeight);
88 if (requiredNumberOfLines > numberOfLines) {
89 requiredNumberOfLines = MIN(requiredNumberOfLines, maximumLines);
90 self.cr_lineHeight = floorf(labelSize.height / requiredNumberOfLines);
91 }
92 }
93
94 @end 77 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/util/CRUILabel+AttributeUtils.h ('k') | ios/chrome/browser/ui/util/CRUILabel+AttributeUtils_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698