From 50a0ecf985bbe81aacfac85192652c2495b769f6 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 1 Feb 2014 20:17:24 +0400 Subject: move UILabel sizeForLabel to category --- Juick/MessageCell.h | 1 + Juick/MessageCell.m | 11 ++++------- Juick/UILabel+Utils.h | 15 +++++++++++++++ Juick/UILabel+Utils.m | 16 ++++++++++++++++ 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 Juick/UILabel+Utils.h create mode 100644 Juick/UILabel+Utils.m (limited to 'Juick') diff --git a/Juick/MessageCell.h b/Juick/MessageCell.h index a042ff3..75d46cf 100644 --- a/Juick/MessageCell.h +++ b/Juick/MessageCell.h @@ -14,6 +14,7 @@ #import "NSString+HTML.h" #import "UIImage+Utils.h" +#import "UILabel+Utils.h" #define kLabelHorizontalInsets 20.0f diff --git a/Juick/MessageCell.m b/Juick/MessageCell.m index 8c2f001..d2b2983 100644 --- a/Juick/MessageCell.m +++ b/Juick/MessageCell.m @@ -80,31 +80,28 @@ // Configure the view for the selected state } -- (CGRect) sizeForLabel:(UILabel *)label width:(CGFloat)width { - return [label.text boundingRectWithSize:(CGSize) {width, CGFLOAT_MAX} options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:label.font} context:nil]; -} - (CGRect) avatarRect { return CGRectMake(kPaddingX, kPaddingY, kAvatarSizeX, kAvatarSizeY); } - (CGRect) bodyRect { - CGRect bodySize = [self sizeForLabel:self.bodyLabel width:(self.contentView.bounds.size.width - kPaddingX * 2)]; + CGRect bodySize = [UILabel sizeForLabel:self.bodyLabel width:(self.contentView.bounds.size.width - kPaddingX * 2)]; return CGRectMake(kPaddingX, kPaddingY + kAvatarSizeY + kPaddingY * 2, bodySize.size.width, bodySize.size.height); } - (CGRect) titleRect { - CGRect titleSize = [self sizeForLabel:self.titleLabel width:self.contentView.bounds.size.width - [self avatarRect].size.width - kPaddingX * 2]; + CGRect titleSize = [UILabel sizeForLabel:self.titleLabel width:self.contentView.bounds.size.width - [self avatarRect].size.width - kPaddingX * 2]; return CGRectMake(kPaddingX + kAvatarSizeX + kPaddingX, kPaddingY, titleSize.size.width, titleSize.size.height); } - (CGRect) timestampRect { - CGRect timeStampSize = [self sizeForLabel:self.timestampLabel width:self.contentView.bounds.size.width - [self avatarRect].size.width - kPaddingX * 2]; + CGRect timeStampSize = [UILabel sizeForLabel:self.timestampLabel width:self.contentView.bounds.size.width - [self avatarRect].size.width - kPaddingX * 2]; return CGRectMake(kPaddingX + [self avatarRect].size.width + kPaddingX, kPaddingY + [self titleRect].size.height + kPaddingY, timeStampSize.size.width, timeStampSize.size.height); } - (CGRect) summaryRect { - CGRect summarySize = [self sizeForLabel:self.summaryLabel width:(self.contentView.bounds.size.width - 20)]; + CGRect summarySize = [UILabel sizeForLabel:self.summaryLabel width:(self.contentView.bounds.size.width - 20)]; float summaryY = 10 + 32 + 10 + [self bodyRect].size.height + 10; if (self.message.attach != nil) { summaryY += [self attachRect].size.height + 10; diff --git a/Juick/UILabel+Utils.h b/Juick/UILabel+Utils.h new file mode 100644 index 0000000..2e9cbb6 --- /dev/null +++ b/Juick/UILabel+Utils.h @@ -0,0 +1,15 @@ +// +// UILabel+Utils.h +// Juick +// +// Created by Vitaly on 01.02.14. +// Copyright (c) 2014 com.juick. All rights reserved. +// + +#import + +@interface UILabel (Utils) + ++ (CGRect) sizeForLabel:(UILabel *)label width:(CGFloat)width; + +@end diff --git a/Juick/UILabel+Utils.m b/Juick/UILabel+Utils.m new file mode 100644 index 0000000..91136d0 --- /dev/null +++ b/Juick/UILabel+Utils.m @@ -0,0 +1,16 @@ +// +// UILabel+Utils.m +// Juick +// +// Created by Vitaly on 01.02.14. +// Copyright (c) 2014 com.juick. All rights reserved. +// + +#import "UILabel+Utils.h" + +@implementation UILabel (Utils) + ++ (CGRect) sizeForLabel:(UILabel *)label width:(CGFloat)width { + return [label.text boundingRectWithSize:(CGSize) {width, CGFLOAT_MAX} options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:label.font} context:nil]; +} +@end -- cgit v1.2.3