diff options
author | lliabraa <lliabraa@chromium.org> | 2014-11-07 07:20:32 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-07 15:20:48 +0000 |
commit | 4981664e4c0407a7fb7443733f989991e3f883a6 (patch) | |
tree | d26ce8063596bf52e523032fb19445bcc46748a5 /ui/ios/NSString+CrStringDrawing.mm | |
parent | 5b86257eca0f11487af5ea5696f89b32181783d4 (diff) | |
download | chromium_src-4981664e4c0407a7fb7443733f989991e3f883a6.zip chromium_src-4981664e4c0407a7fb7443733f989991e3f883a6.tar.gz chromium_src-4981664e4c0407a7fb7443733f989991e3f883a6.tar.bz2 |
[ui/ios] Add helper methods for getting the bounding size of some text.
These helpers are meant to ease the transition from the deprecated
|sizeWithFont:constrainedToSize:| methods. They'll also help reduce
boilerplate compared to the iOS method
|boundingRectWithSize:options:attributes:context:|
BUG=364419
Review URL: https://codereview.chromium.org/704283002
Cr-Commit-Position: refs/heads/master@{#303237}
Diffstat (limited to 'ui/ios/NSString+CrStringDrawing.mm')
-rw-r--r-- | ui/ios/NSString+CrStringDrawing.mm | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ui/ios/NSString+CrStringDrawing.mm b/ui/ios/NSString+CrStringDrawing.mm index 214b0c1..e9274e9 100644 --- a/ui/ios/NSString+CrStringDrawing.mm +++ b/ui/ios/NSString+CrStringDrawing.mm @@ -9,6 +9,20 @@ @implementation NSString (CrStringDrawing) +- (CGRect)cr_boundingRectWithSize:(CGSize)size + font:(UIFont*)font { + NSDictionary* attributes = font ? @{NSFontAttributeName: font} : @{}; + return [self boundingRectWithSize:size + options:NSStringDrawingUsesLineFragmentOrigin + attributes:attributes + context:nil]; +} + +- (CGSize)cr_boundingSizeWithSize:(CGSize)size + font:(UIFont*)font { + return [self cr_boundingRectWithSize:size font:font].size; +} + - (CGSize)cr_pixelAlignedSizeWithFont:(UIFont*)font { DCHECK(font) << "|font| can not be nil; it is used as a NSDictionary value"; NSDictionary* attributes = @{ NSFontAttributeName : font }; |