簡體   English   中英

如何更改titleForHeaderInSection的字體顏色?

[英]How can i change the font color for titleForHeaderInSection?

這是我當前必須顯示的文本,但是我似乎無法更改titleForHeaderInSection的字體顏色。

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

我將如何更改字體顏色,例如可以是紅色?

編輯:我忘了提,我沒有使用Interface Builder來做到這一點。

您需要創建一個自定義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];
}

UITableView委托中使用:

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

返回自定義UIView對象,您可以在其中更改所需的內容。 鏈接

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM