4
我可以在UITableView中自定義節頭文件嗎? (字體,圖像...) 我想實現這樣的事情:我可以在UITableView中自定義節標題嗎? (字體,圖片...)
這可能嗎? 我已經得到了我想要的單元格,但沒有分區標題。 謝謝。
我可以在UITableView中自定義節頭文件嗎? (字體,圖像...) 我想實現這樣的事情:我可以在UITableView中自定義節標題嗎? (字體,圖片...)
這可能嗎? 我已經得到了我想要的單元格,但沒有分區標題。 謝謝。
您可以通過實現方法tableView:viewForHeaderInSection:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
// create and return a custom UIView to use for the section here
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *sectionName = nil;
switch (section) {
case 0:
sectionName = [NSString stringWithFormat:@"Header Text 1"];
break;
case 1:
sectionName = [NSString stringWithFormat:@"Header Text 2"];
break;
case 2:
sectionName = [NSString stringWithFormat:@"Header Text 3"];
break;
}
UILabel *sectionHeader = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)] autorelease];
sectionHeader.backgroundColor = [UIColor clearColor];
sectionHeader.font = [UIFont boldSystemFontOfSize:18];
sectionHeader.textColor = [UIColor whiteColor];
sectionHeader.text = sectionName;
return sectionHeader;
}
感謝您的回覆爲您的tableView的節頭的自定義視圖,我會嘗試。但是,我應該使用什麼尺寸或高度?我是否必須通過代碼創建它?我可以使用故事板嗎?謝謝! – Ricardo 2012-04-22 00:36:18
我發現這個tableView:heightForHeaderInSection:非常感謝。 – Ricardo 2012-04-22 00:38:00