0
我有TableView與部分,部分是國家和我從我的核心數據實體中獲取它們。我爲我的tableview設置了一個背景圖像,現在我想更改該部分的標題顏色。我怎樣才能做到這一點?這是我的代碼到目前爲止。更改UITableView部分標題的顏色
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections]objectAtIndex:section];
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
// Create label with section title
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(20, 6, 300, 30);
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.shadowColor = [UIColor blackColor];
label.shadowOffset = CGSizeMake(0.0, 1.0);
label.font = [UIFont boldSystemFontOfSize:16];
//label.text = sectionTitle;
label.text=[sectionInfo name];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width,tableView.bounds.size.height)];
[view addSubview:label];
return [sectionInfo name];
}
當我嘗試我的代碼我得到一個錯誤
非常感謝你,它的工作原理!!!! – 2012-04-25 09:33:55