Created
April 17, 2012 12:31
-
-
Save chrishulbert/2405688 to your computer and use it in GitHub Desktop.
Helper to style grouped table views on the iphone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // Helpers.m | |
| // | |
| // Created by Chris Hulbert on 17/04/12. | |
| // | |
| #import "Helpers.h" | |
| @implementation Helpers | |
| // Make a normal looking table header with a black label | |
| + (UIView*)styledTableHeader:(NSString*)text { | |
| UILabel* l = [[UILabel alloc] init]; | |
| l.frame = CGRectMake(20, 0, 300, 36); | |
| l.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; | |
| l.backgroundColor = [UIColor clearColor]; | |
| l.text = text; | |
| l.shadowOffset = CGSizeMake(0, 1); | |
| l.shadowColor = [UIColor colorWithWhite:1 alpha:0.5]; | |
| // Label is wrapped in a view so we can offset it 20px right | |
| UIView* v = [[UIView alloc] init]; | |
| [v addSubview:l]; | |
| return v; | |
| } | |
| + (int)styledTableHeaderHeight { | |
| return 36; | |
| } | |
| // Apply my styles to a table view | |
| + (void)styleTableView:(UITableView*)tableView { | |
| tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; // Remove the etch | |
| tableView.separatorColor = [UIColor blackColor]; // Harsher separator to contrast the 50% black | |
| tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"table_bg.jpg"]]; | |
| } | |
| // Style a cell just prior to displaying it | |
| + (void)styleWillDisplayCell:(UITableViewCell *)cell { | |
| cell.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; | |
| cell.textLabel.backgroundColor = [UIColor clearColor]; | |
| cell.textLabel.textColor = [UIColor whiteColor]; | |
| cell.textLabel.shadowColor = [UIColor blackColor]; | |
| cell.detailTextLabel.backgroundColor = [UIColor clearColor]; | |
| cell.detailTextLabel.textColor = [UIColor colorWithWhite:0.8 alpha:1]; | |
| cell.detailTextLabel.shadowColor = [UIColor blackColor]; | |
| } | |
| // For UITableViewCellStyleValue2, this does the textlabel grey and the main white | |
| + (void)styleWillDisplayCell2:(UITableViewCell *)cell { | |
| cell.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; | |
| cell.textLabel.backgroundColor = [UIColor clearColor]; | |
| cell.textLabel.textColor = [UIColor colorWithWhite:0.8 alpha:1]; | |
| cell.textLabel.shadowColor = [UIColor blackColor]; | |
| cell.detailTextLabel.backgroundColor = [UIColor clearColor]; | |
| cell.detailTextLabel.textColor = [UIColor whiteColor]; | |
| cell.detailTextLabel.shadowColor = [UIColor blackColor]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment