Skip to content

Commit 88a2b25

Browse files
committed
Added compatibility with plain UITableViews
1 parent aa2b977 commit 88a2b25

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

Classes/ios/FUICellBackgroundView.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ - (void)layoutSubviews {
4343
}
4444

4545
- (void)drawRect:(CGRect)aRect {
46+
//Determine tableView style
47+
UITableView* tableView = (UITableView*)self.superview.superview;
48+
if (tableView.style != UITableViewStyleGrouped)
49+
self.cornerRadius = 0.f;
50+
4651
CGContextRef c = UIGraphicsGetCurrentContext();
4752

4853
int lineWidth = 1;
@@ -96,6 +101,10 @@ - (void)drawRect:(CGRect)aRect {
96101

97102
CGContextSetFillColorWithColor(c, self.backgroundColor.CGColor);
98103
CGContextFillRect(c, self.bounds);
104+
if (self.cornerRadius == 0.f) {
105+
CGContextSetFillColorWithColor(c, self.separatorColor.CGColor);
106+
CGContextFillRect(c, CGRectMake(0, self.bounds.size.height - self.separatorHeight, self.bounds.size.width, self.bounds.size.height - self.separatorHeight));
107+
}
99108

100109
CGContextAddPath(c, path);
101110
CGPathRelease(path);

Example/FlatUIKitExample/TableViewController.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ - (void)viewDidLoad
3434

3535
//Set the separator color
3636
self.tableView.separatorColor = [UIColor cloudsColor];
37+
38+
//Set the background color
39+
self.tableView.backgroundColor = [UIColor cloudsColor];
40+
self.tableView.backgroundView = nil;
3741
}
3842

3943
#pragma mark - Table view data source
@@ -57,12 +61,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
5761
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
5862

5963
if (!cell) {
60-
cell = [UITableViewCell configureFlatCellWithColor:[UIColor midnightBlueColor] selectedColor:[UIColor cloudsColor] style:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
64+
cell = [UITableViewCell configureFlatCellWithColor:[UIColor greenSeaColor] selectedColor:[UIColor cloudsColor] style:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
6165
cell.cornerRadius = 5.f; //Optional
6266
cell.separatorHeight = 2.f; //Optional
6367
}
6468

65-
cell.textLabel.text = [NSString stringWithFormat:@"Row %d", indexPath.row];
69+
cell.textLabel.text = [NSString stringWithFormat:@"Section %d Row %d", indexPath.section, indexPath.row];
6670

6771
return cell;
6872
}

Example/FlatUIKitExample/ViewController.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ - (void)viewDidLoad
4646
cornerRadius:3
4747
whenContainedIn:[UINavigationBar class], nil];
4848

49-
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Button"
49+
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Plain Table"
5050
style:UIBarButtonItemStylePlain
51-
target:nil
52-
action:nil];
51+
target:self
52+
action:@selector(showPlainTableView:)];
5353
[self.navigationItem.rightBarButtonItem removeTitleShadow];
5454

55-
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"TableView"
55+
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Grouped Table"
5656
style:UIBarButtonItemStylePlain
5757
target:self
5858
action:@selector(showTableView:)];
@@ -139,4 +139,9 @@ - (void)showTableView:(id)sender {
139139
[self.navigationController pushViewController:tableViewController animated:YES];
140140
}
141141

142+
- (void)showPlainTableView:(id)sender {
143+
TableViewController* tableViewController = [[TableViewController alloc] initWithStyle:UITableViewStylePlain];
144+
[self.navigationController pushViewController:tableViewController animated:YES];
145+
}
146+
142147
@end

0 commit comments

Comments
 (0)