forked from pilot34/P34Utils
/
UITableViewCell+Utils.m
46 lines (38 loc) · 1.14 KB
/
UITableViewCell+Utils.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// UITableViewCell+Utils.m
// Intuit
//
// Created by Глеб Тарасов on 21.01.12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "UITableViewCell+Utils.h"
@implementation UITableViewCell (Utils)
+ (CGFloat)heightForText:(NSString *)text withImage:(BOOL)image withAccessory:(UITableViewCellAccessoryType)accessoryType withFont:(UIFont *)font inTableView:(UITableView *)tableView
{
CGFloat contentWidth = tableView.frame.size.width;
// reduce width for accessories
switch (accessoryType)
{
case UITableViewCellAccessoryDisclosureIndicator:
case UITableViewCellAccessoryCheckmark:
contentWidth -= 20.0f;
break;
case UITableViewCellAccessoryDetailDisclosureButton:
contentWidth -= 33.0f;
break;
case UITableViewCellAccessoryNone:
break;
}
// reduce width for grouped table views
if (tableView.style == UITableViewStyleGrouped)
{
contentWidth -= 19.0f;
}
// image width
if (image)
contentWidth -= 40.0f;
return [text heightWithFont:font
constrainedToWidth:contentWidth
lineBreakMode:UILineBreakModeWordWrap] + 20.f;
}
@end