我的應用程序看起來就像iPhone上的默認地址簿應用程序。對於每個字母表,地址簿(A,B ...)中都有一個以灰色漸變背景色顯示的部分標題。是否有可能將該默認顏色覆蓋爲某種其他色調顏色?更改節標題標題(普通桌面視圖)的背景顏色
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
你可能也想實現高度的方法來正確地確保您的新欄目視圖顯示:
我的應用程序看起來就像iPhone上的默認地址簿應用程序。對於每個字母表,地址簿(A,B ...)中都有一個以灰色漸變背景色顯示的部分標題。是否有可能將該默認顏色覆蓋爲某種其他色調顏色?更改節標題標題(普通桌面視圖)的背景顏色
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
你可能也想實現高度的方法來正確地確保您的新欄目視圖顯示:
您可以通過實現在的UITableViewDelegate下面的方法替換一個UITableView的節標題:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
爲了改變節頭的顏色,創建一個UIView與在其內一個UIImageView,和用於噸一個UILabel分部的分機。將圖像添加到UIImageView以獲取背景的外觀。
AFAIK,你不能操縱截面視圖的tintColor。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
// create the parent view that will hold header Label
UIView* customView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 25.0)];
// create the button object
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
headerLabel.backgroundColor = [UIColor blackColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor whiteColor];
headerLabel.highlightedTextColor = [UIColor whiteColor];
headerLabel.font = [UIFont boldSystemFontOfSize:20];
headerLabel.frame = CGRectMake(0.0, 0.0, 320.0, 22.0);
// If you want to align the header text as centered
//headerLabel.frame = CGRectMake(150.0, 0.0, 300.0, 44.0);
headerLabel.text = @"Name of header";
[customView addSubview:headerLabel];
return customView;
}