Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
805 - 1
//
2
//  InAppSettingsTableCell.m
3
//  InAppSettingsTestApp
4
//
5
//  Created by David Keegan on 11/21/09.
6
//  Copyright 2009 InScopeApps{+}. All rights reserved.
7
//
8
 
9
#import "InAppSettingsTableCell.h"
10
#import "InAppSettingsConstants.h"
11
 
12
@implementation InAppSettingsTableCell
13
 
14
@synthesize setting;
15
@synthesize titleLabel, valueLabel;
16
@synthesize valueInput;
17
@synthesize canSelectCell;
18
 
19
#pragma mark Cell lables
20
 
21
- (void)setTitle{
22
    self.titleLabel.text = [self.setting localizedTitle];
23
 
24
    CGSize titleSize = [self.titleLabel.text sizeWithFont:self.titleLabel.font];
25
 
26
    CGFloat maxTitleWidth = InAppSettingsCellTitleMaxWidth;
27
    if([self.setting isType:InAppSettingsPSToggleSwitchSpecifier]){
28
        maxTitleWidth = InAppSettingsCellTitleMaxWidth-(InAppSettingsCellToggleSwitchWidth+InAppSettingsCellPadding);
29
    }else if(self.accessoryType == UITableViewCellAccessoryDisclosureIndicator){
30
        maxTitleWidth = InAppSettingsCellTitleMaxWidth-(InAppSettingsCellDisclosureIndicatorWidth+InAppSettingsCellPadding);
31
    }
32
    if(titleSize.width > maxTitleWidth){
33
        titleSize.width = maxTitleWidth;
34
    }
35
 
36
    CGRect titleFrame = self.titleLabel.frame;
37
    titleFrame.size = titleSize;
38
    titleFrame.origin.x = InAppSettingsCellPadding;
39
    titleFrame.origin.y = (CGFloat)round((self.contentView.frame.size.height*0.5f)-(titleSize.height*0.5f))-InAppSettingsOffsetY;
40
    self.titleLabel.frame = titleFrame;
41
}
42
 
43
- (void)setDetail{
44
    [self setDetail:[self.setting getValue]];
45
}
46
 
47
- (void)setDetail:(NSString *)detail{
48
    //the detail is not localized
49
    self.valueLabel.text = detail;
50
 
51
    CGSize valueSize = [self.valueLabel.text sizeWithFont:self.valueLabel.font];
52
 
53
    CGRect valueFrame = self.valueLabel.frame;
54
    CGFloat titleRightSide = self.titleLabel.frame.size.width+InAppSettingsTablePadding;
55
    if([self.setting isType:InAppSettingsPSMultiValueSpecifier] && [[self.setting localizedTitle] length] == 0){
56
            valueFrame.origin.x = InAppSettingsCellPadding;
57
    }else{
58
        valueFrame.origin.x = (InAppSettingsScreenWidth-(InAppSettingsTotalTablePadding+InAppSettingsCellPadding))-valueSize.width;
59
        if(self.accessoryType == UITableViewCellAccessoryDisclosureIndicator){
60
            valueFrame.origin.x -= InAppSettingsCellDisclosureIndicatorWidth+InAppSettingsCellPadding;
61
        }
62
        if(titleRightSide >= valueFrame.origin.x){
63
            valueFrame.origin.x = titleRightSide;
64
        }
65
    }
66
    valueFrame.origin.y = (CGFloat)round((self.contentView.frame.size.height*0.5f)-(valueSize.height*0.5f))-InAppSettingsOffsetY;
67
    valueFrame.size.width = InAppSettingsScreenWidth-(valueFrame.origin.x+InAppSettingsTotalTablePadding+InAppSettingsCellPadding);
68
    if(self.accessoryType == UITableViewCellAccessoryDisclosureIndicator){
69
        valueFrame.size.width -= InAppSettingsCellDisclosureIndicatorWidth+InAppSettingsCellPadding;
70
    }
71
 
72
    //if the width is less then 0 just hide the label
73
    if(valueFrame.size.width <= 0){
74
        self.valueLabel.hidden = YES;
75
    }else{
76
        self.valueLabel.hidden = NO;
77
    }
78
    valueFrame.size.height = valueSize.height;
79
    self.valueLabel.frame = valueFrame;
80
}
81
 
82
- (void)setDisclosure:(BOOL)disclosure{
83
    if(disclosure){
84
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
85
    }
86
    else{
87
        self.accessoryType = UITableViewCellAccessoryNone;
88
    }
89
}
90
 
91
- (void)setCanSelectCell:(BOOL)value{
92
    if(value){
93
        self.selectionStyle = UITableViewCellSelectionStyleBlue;
94
    }else{
95
        self.selectionStyle = UITableViewCellSelectionStyleNone;
96
    }
97
    canSelectCell = value;
98
}
99
 
100
#pragma mark -
101
 
102
- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier{
103
    //the docs say UITableViewCellStyleValue1 is used for settings,
104
    //but it doesn't look 100% the same so we will just draw our own UILabels
105
    #if InAppSettingsUseNewCells
106
    self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
107
    #else
108
    self = [super initWithFrame:CGRectZero reuseIdentifier:reuseIdentifier];
109
    #endif
110
 
111
    if(self != nil){
112
        self.canSelectCell = NO;
113
    }
114
 
115
    return self;
116
}
117
 
118
#pragma mark implement in cell
119
 
120
- (void)setUIValues{
121
    //implement this per cell type
122
}
123
 
124
- (void)setValueDelegate:(id)delegate{
125
    //implement in cell
126
}
127
 
128
- (void)setupCell{
129
    //setup title label
130
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
131
    self.titleLabel.font = InAppSettingsBoldFont;
132
    self.titleLabel.highlightedTextColor = [UIColor whiteColor];
133
    self.titleLabel.backgroundColor = [UIColor clearColor];
134
//    self.titleLabel.backgroundColor = [UIColor greenColor];
135
    [self.contentView addSubview:self.titleLabel];
136
 
137
    //setup value label
138
    self.valueLabel = [[UILabel alloc] initWithFrame:CGRectZero];
139
    self.valueLabel.font = InAppSettingsNormalFont;
140
    self.valueLabel.textColor = InAppSettingsBlue;
141
    self.valueLabel.highlightedTextColor = [UIColor whiteColor];
142
    self.valueLabel.backgroundColor = [UIColor clearColor];
143
//    self.valueLabel.backgroundColor = [UIColor redColor];
144
    [self.contentView addSubview:self.valueLabel];
145
}
146
 
147
- (void)dealloc{
148
    [setting release];
149
    [titleLabel release];
150
    [valueLabel release];
151
    self.valueInput = nil;
152
    [super dealloc];
153
}
154
 
155
@end