2009-10-05 42 views
4
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 

{ 

} 


我的目標C很新.......................通過這種方法我們可以得到標題部分的標題,但是如何改變那個字符串的顏色?我可以這麼做........如果有人知道,請告訴我。改變titleFor頭的顏色部分

Regards

回答

2

意識到你返回視圖不被UITableView的(OS 3.1.2至少,似乎顯示這個問題)保留。這導致在執行到viewDidLoad之前發生難以找到的崩潰。

表格視圖並不像您想象的那樣抓住您的視圖。它要求他們全部,然後再次請求他們,有時甚至多次,因此在每個請求上生成它們都是非常低效的。

2

改爲使用tableView:viewForHeaderInSection:。這樣你就可以配置一個UILabel或任何你喜歡的東西(包括字體,透明度,顏色等),並且tableview將使用該視圖作爲標題而不是默認視圖。

5

您可以嘗試如下因素: 頭有兩個自定義標籤

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection: 
                 (NSInteger)section { 
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 
    tableView.bounds.size.width, 22)]; 

    NSString *dateStr = [[self.data allKeys] objectAtIndex:section]; 
    CGFloat labelWidth = tableView.bounds.size.width/2; 
    CGFloat padding = 5.0; 

    UILabel *labelOne = [[UILabel alloc] initWithFrame:CGRectMake 
         (padding, 0, (labelWidth - padding), 22)]; 
    labelOne.backgroundColor = [UIColor clearColor]; 
    labelOne.textAlignment = UITextAlignmentLeft; 
    labelOne.text = dateStr; 

    UILabel *labelTwo = [[UILabel alloc] initWithFrame:CGRectMake 
    (labelWidth, 0, (labelWidth - padding), 22)]; 
    labelTwo.backgroundColor = [UIColor clearColor]; 
    labelTwo.textAlignment = UITextAlignmentRight; 
    labelTwo.text = @"This is Label TWO"; 

    [headerView addSubview:labelOne]; 
    [headerView addSubview:labelTwo]; 

    [labelOne release]; 
    [labelTwo release]; 

    return headerView; 
} 
1

請使用以下代碼&改變你的UITableView標題的顏色

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *tempHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0,0,320,44)]; 
    tempHeaderView.backgroundColor=[UIColor clearColor]; 
    UILabel *tempHeaderLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,0,320,44)]; 
    tempHeaderLabel.backgroundColor=[UIColor clearColor]; 
    [email protected]"HEADER"; 
    [tempHeaderView addSubView: tempHeaderLabel]; 
    return tempHeaderView; 
}