forked from pokeb/asi-http-request
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInfoCell.m
64 lines (55 loc) · 2.01 KB
/
InfoCell.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// InfoCell.m
// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details
//
// Created by Ben Copsey on 17/06/2010.
// Copyright 2010 All-Seeing Interactive. All rights reserved.
//
#import "InfoCell.h"
@implementation InfoCell
+ (id)cell
{
InfoCell *cell = [[[InfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"InfoCell"] autorelease];
if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad
[[cell textLabel] setFont:[UIFont systemFontOfSize:14]];
} else {
[[cell textLabel] setFont:[UIFont systemFontOfSize:13]];
}
[[cell textLabel] setLineBreakMode:UILineBreakModeWordWrap];
[[cell textLabel] setNumberOfLines:0];
if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(10,10,48,48)] autorelease];
[imageView setImage:[UIImage imageNamed:@"info.png"]];
[[cell contentView] addSubview:imageView];
}
return cell;
}
- (void)layoutSubviews
{
[super layoutSubviews];
int tablePadding = 40;
int tableWidth = [[self superview] frame].size.width;
if (tableWidth > 480) { // iPad
tablePadding = 110;
[[self textLabel] setFrame:CGRectMake(70,10,tableWidth-tablePadding-70,[[self class] neededHeightForDescription:[[self textLabel] text] withTableWidth:tableWidth])];
} else {
[[self textLabel] setFrame:CGRectMake(10,10,tableWidth-tablePadding,[[self class] neededHeightForDescription:[[self textLabel] text] withTableWidth:tableWidth])];
}
}
+ (NSUInteger)neededHeightForDescription:(NSString *)description withTableWidth:(NSUInteger)tableWidth
{
int tablePadding = 40;
int offset = 0;
int textSize = 13;
if (tableWidth > 480) { // iPad
tablePadding = 110;
offset = 70;
textSize = 14;
}
CGSize labelSize = [description sizeWithFont:[UIFont systemFontOfSize:textSize] constrainedToSize:CGSizeMake(tableWidth-tablePadding-offset,1000) lineBreakMode:UILineBreakModeWordWrap];
if (labelSize.height < 48) {
return 58;
}
return labelSize.height;
}
@end