From f01fb8921dbcf3b201a3f6d485b54374978a4f2b Mon Sep 17 00:00:00 2001 From: mhupman Date: Tue, 14 Jan 2014 10:27:33 -0500 Subject: [PATCH] =?UTF-8?q?Prompt=20cell=20required=20width=20calculation?= =?UTF-8?q?=20wasn=E2=80=99t=20taking=20the=20UILabel=E2=80=99s=20font=20i?= =?UTF-8?q?nto=20account=20so=20it=20wasn=E2=80=99t=20growing=20wide=20eno?= =?UTF-8?q?ugh.=20=20Fix.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MBContactPicker/MBContactCollectionViewPromptCell.m | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/MBContactPicker/MBContactCollectionViewPromptCell.m b/MBContactPicker/MBContactCollectionViewPromptCell.m index aa1c46a..6851e67 100644 --- a/MBContactPicker/MBContactCollectionViewPromptCell.m +++ b/MBContactPicker/MBContactCollectionViewPromptCell.m @@ -78,15 +78,22 @@ - (void)setup - (void)setPrompt:(NSString *)prompt { - _prompt = prompt; + _prompt = prompt.copy; self.promptLabel.text = prompt; } +static UILabel *templateLabel; + + (CGFloat)widthWithPrompt:(NSString *)prompt { + if (!templateLabel) + { + templateLabel = [[UILabel alloc] init]; + } + CGRect frame = [prompt boundingRectWithSize:(CGSize){ .width = CGFLOAT_MAX, .height = CGFLOAT_MAX } options:NSStringDrawingUsesLineFragmentOrigin - attributes:nil + attributes:@{ NSFontAttributeName : templateLabel.font } context:nil]; return ceilf(frame.size.width); }