如何更改titleForHeaderInSection的字体颜色?

时间:2011-02-01 16:55:13

标签: iphone fonts colors

这是我目前要显示文本的内容,但我似乎无法更改titleForHeaderInSection的字体颜色。

- (NSString *)tableView:(UITableView *)tableView 
                                       titleForHeaderInSection:(NSInteger)section 
{
    if(section == 0)
        return @"Information";
    if(section == 1)
        return @"Categorize Information";
    return nil;
}

我怎样才能更改字体颜色,例如它可能是红色的?

编辑: 我忘了提,我不是在使用Interface Builder做这件事。

2 个答案:

答案 0 :(得分:2)

您需要创建自定义UIView。我发现这样做的最好方法是在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];
}

答案 1 :(得分:1)

UITableView委托使用:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

返回自定义UIView对象,您可以在其中更改所需内容。请参阅link

相关问题