-
Notifications
You must be signed in to change notification settings - Fork 9
/
MultiLineTableViewCellStyle2.m
82 lines (66 loc) · 2.08 KB
/
MultiLineTableViewCellStyle2.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// MultiLineTableViewCellStyle2.m
// MyKeePass
//
// Created by Qiang Yu on 12/18/09.
// Copyright 2009 Qiang Yu. All rights reserved.
//
#import "MultiLineTableViewCellStyle2.h"
#define LABEL_WIDTH (70.0f)
#define DETAIL_WIDTH (200.0f)
static UIFont * labelFont;
static UIFont * detailFont;
@implementation MultiLineTableViewCellStyle2
@synthesize _trueValue;
-(void)dealloc{
[_trueValue release];
[super dealloc];
}
-(id)init:(NSString *)reuseIdentifier{
if(self = [super initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:reuseIdentifier]){
self.textLabel.numberOfLines = 0;
if(!labelFont)
labelFont = [UIFont boldSystemFontOfSize:LABLE_SIZE];
self.textLabel.font = labelFont;
self.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
self.detailTextLabel.numberOfLines = 0;
if(!detailFont)
detailFont = [UIFont systemFontOfSize:DETAIL_SIZE];
self.detailTextLabel.font = detailFont;
}
return self;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender{
if(action == @selector(copy:)){
return self.detailTextLabel.text!=nil&&[self.detailTextLabel.text length]>0;
}
return NO;
}
- (void)copy:(id)sender{
UIPasteboard * gpBoard = [UIPasteboard generalPasteboard];
if(_trueValue)
gpBoard.string = _trueValue;
else
gpBoard.string = self.detailTextLabel.text;
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
+ (CGFloat) heightOfCellWithLabel:(NSString *)label detail:(NSString *)detail{
CGSize labelSize = {0, 0};
CGSize detailSize = {0, 0};
if(!labelFont)
labelFont = [UIFont boldSystemFontOfSize:LABLE_SIZE];
if(!detailFont)
detailFont = [UIFont systemFontOfSize:DETAIL_SIZE];
if(label && ![label isEqualToString:@""]){
labelSize = [label sizeWithFont:labelFont constrainedToSize:CGSizeMake(LABEL_WIDTH, CGFLOAT_MAX)
lineBreakMode:UILineBreakModeWordWrap];
}
if(detail && ![detail isEqualToString:@""]){
detailSize = [detail sizeWithFont:detailFont constrainedToSize:CGSizeMake(DETAIL_WIDTH, CGFLOAT_MAX)
lineBreakMode:UILineBreakModeWordWrap];
}
return MAX(labelSize.height, detailSize.height)+12;
}
@end