root / asi-http-request-with-pithos / iPhone Sample / InfoCell.m @ be116d22
History | View | Annotate | Download (2 kB)
1 |
// |
---|---|
2 |
// InfoCell.m |
3 |
// Part of the ASIHTTPRequest sample project - see http://allseeing-i.com/ASIHTTPRequest for details |
4 |
// |
5 |
// Created by Ben Copsey on 17/06/2010. |
6 |
// Copyright 2010 All-Seeing Interactive. All rights reserved. |
7 |
// |
8 |
|
9 |
#import "InfoCell.h" |
10 |
|
11 |
|
12 |
@implementation InfoCell |
13 |
|
14 |
+ (id)cell |
15 |
{ |
16 |
InfoCell *cell = [[[InfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"InfoCell"] autorelease]; |
17 |
if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad |
18 |
[[cell textLabel] setFont:[UIFont systemFontOfSize:14]]; |
19 |
} else { |
20 |
[[cell textLabel] setFont:[UIFont systemFontOfSize:13]]; |
21 |
} |
22 |
[[cell textLabel] setLineBreakMode:UILineBreakModeWordWrap]; |
23 |
[[cell textLabel] setNumberOfLines:0]; |
24 |
|
25 |
if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad |
26 |
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(10,10,48,48)] autorelease]; |
27 |
[imageView setImage:[UIImage imageNamed:@"info.png"]]; |
28 |
[[cell contentView] addSubview:imageView]; |
29 |
} |
30 |
return cell; |
31 |
} |
32 |
|
33 |
- (void)layoutSubviews |
34 |
{ |
35 |
[super layoutSubviews]; |
36 |
int tablePadding = 40; |
37 |
int tableWidth = [[self superview] frame].size.width; |
38 |
if (tableWidth > 480) { // iPad |
39 |
tablePadding = 110; |
40 |
[[self textLabel] setFrame:CGRectMake(70,10,tableWidth-tablePadding-70,[[self class] neededHeightForDescription:[[self textLabel] text] withTableWidth:tableWidth])]; |
41 |
} else { |
42 |
[[self textLabel] setFrame:CGRectMake(10,10,tableWidth-tablePadding,[[self class] neededHeightForDescription:[[self textLabel] text] withTableWidth:tableWidth])]; |
43 |
} |
44 |
|
45 |
} |
46 |
|
47 |
+ (NSUInteger)neededHeightForDescription:(NSString *)description withTableWidth:(NSUInteger)tableWidth |
48 |
{ |
49 |
int tablePadding = 40; |
50 |
int offset = 0; |
51 |
int textSize = 13; |
52 |
if (tableWidth > 480) { // iPad |
53 |
tablePadding = 110; |
54 |
offset = 70; |
55 |
textSize = 14; |
56 |
} |
57 |
CGSize labelSize = [description sizeWithFont:[UIFont systemFontOfSize:textSize] constrainedToSize:CGSizeMake(tableWidth-tablePadding-offset,1000) lineBreakMode:UILineBreakModeWordWrap]; |
58 |
if (labelSize.height < 48) { |
59 |
return 58; |
60 |
} |
61 |
return labelSize.height; |
62 |
} |
63 |
|
64 |
@end |