-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUITableViewCell+FlatUI.m
executable file
·56 lines (45 loc) · 2.11 KB
/
UITableViewCell+FlatUI.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
//
// UITableViewCell+FlatUI.m
// FlatUIKitExample
//
// Created by Maciej Swic on 2013-05-31.
//
//
#import "UITableViewCell+FlatUI.h"
#import "FUICellBackgroundView.h"
#import <objc/runtime.h>
@implementation UITableViewCell (FlatUI)
@dynamic cornerRadius, separatorHeight;
+ (UITableViewCell*) configureFlatCellWithColor:(UIColor *)color selectedColor:(UIColor *)selectedColor reuseIdentifier:(NSString*)reuseIdentifier inTableView:(UITableView *)tableView {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
[cell configureFlatCellWithColor:color selectedColor:selectedColor];
return cell;
}
- (void) configureFlatCellWithColor:(UIColor *)color selectedColor:(UIColor *)selectedColor {
FUICellBackgroundView* backgroundView = [FUICellBackgroundView new];
backgroundView.backgroundColor = color;
self.backgroundView = backgroundView;
FUICellBackgroundView* selectedBackgroundView = [FUICellBackgroundView new];
selectedBackgroundView.backgroundColor = selectedColor;
self.selectedBackgroundView = selectedBackgroundView;
//The labels need a clear background color or they will look very funky
self.textLabel.backgroundColor = [UIColor clearColor];
if ([self respondsToSelector:@selector(detailTextLabel)])
self.detailTextLabel.backgroundColor = [UIColor clearColor];
//Guess some good text colors
self.textLabel.textColor = selectedColor;
self.textLabel.highlightedTextColor = color;
if ([self respondsToSelector:@selector(detailTextLabel)]) {
self.detailTextLabel.textColor = selectedColor;
self.detailTextLabel.highlightedTextColor = color;
}
}
- (void)setCornerRadius:(CGFloat)cornerRadius {
[(FUICellBackgroundView*)self.backgroundView setCornerRadius:cornerRadius];
[(FUICellBackgroundView*)self.selectedBackgroundView setCornerRadius:cornerRadius];
}
- (void)setSeparatorHeight:(CGFloat)separatorHeight {
[(FUICellBackgroundView*)self.backgroundView setSeparatorHeight:separatorHeight];
[(FUICellBackgroundView*)self.selectedBackgroundView setSeparatorHeight:separatorHeight];
}
@end