How can i change the font color for titleForHeaderInSection?
This is what i currently have to display my text, but i can't seem to be able to开发者_如何学编程 change the font color of titleForHeaderInSection.
- (NSString *)tableView:(UITableView *)tableView
titleForHeaderInSection:(NSInteger)section
{
if(section == 0)
return @"Information";
if(section == 1)
return @"Categorize Information";
return nil;
}
How would i be able to change the font color so it could be red for example?
Edit: I forgot to mention, i'm not using Interface Builder do do this.
You need to create a custom UIView. The best way I have found to do this is in Interface Builder.
.h
@interface MyViewController : UITableViewController {
IBOutlet UIView *headerView;
}
@property (nonatomic, retain) UIView *headerView;
@end
.m
#import “MyViewController.h”
@implementation MyViewController
@synthesize headerView;
#pragma mark Table Stuff
- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section
{
/* create a UIView here */
return headerView;
}
#pragma mark Memory Management
- (void)dealloc {
[headerView release];
[super dealloc];
}
In the UITableView
delegate use:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
to return a custom UIView object, where you can change what you need. See link.
精彩评论