2012-02-21 98 views
0

我已經使用Group-style創建了UITableView。我的桌子上只有一個組。在UITableView中的標題標題旁邊添加圖像

這裏是我的兩個問題:

1)如何在頭球頂我旁邊的標題顯示的圖片?基本上我想把我們公司的標誌放在那個標題旁邊。

2)我可以更改標題中的背景顏色(我不喜歡灰色)嗎?我可以調整標題的高度嗎?

回答

0

只返回一個自定義視圖您的標題是這樣的:

//Draws a custom view for the header instructions 
-(UIView*)tableView:(UITableView*) tableView viewForHeaderInSection:(NSInteger)section; 
{ 
    if ([tableView numberOfRowsInSection:section] != 0) // To handle nil entries 
    { 
    UIView* headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 60)] autorelease]; 

     // set up whatever view you want here. E.g. 

    UILabel* headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, headerView.frame.size.width - 20.0, headerView.frame.size.height)]; 

     headerLabel.text = @"Tap items in the list to pin them.\nTap the Remix button to clear all unpinned items"; 
     headerLabel.numberOfLines = 0; 

    headerLabel.font = [UIFont fontWithName:@"HelveticaNeueLTStd-Lt" size: 14]; 
    headerLabel.backgroundColor = [UIColor clearColor]; 
    headerLabel.textColor = [UIColor colorWithRed:kColorRed green:kColorGreen blue:kColorBlue alpha:1]; 
    headerLabel.userInteractionEnabled = NO; 
     headerLabel.textAlignment = UITextAlignmentCenter; 

    headerView.backgroundColor = [UIColor clearColor]; 

    [headerView setTag:010]; 
    [headerView setAlpha:1]; 

    [headerView addSubview:headerLabel]; 
    [headerLabel release]; 
    return headerView; 
    } 
    else { 
     return nil; // again to handle nil tables. You should be nice and at least show an error label on the view. 
    }  
} 

這給了你這樣的:

How it should only work

+0

非常感謝您的幫助。我確實實施了這個方法,但是我的程序崩潰了。我正在使用ARC,因此我刪除了所有的自動重新發布 – xcoderookie 2012-02-21 22:29:55

+0

唉,希望它以後能夠正常工作。如果您發現問題的解決方案,請確保勾選複選標記! – rinzler 2012-02-26 03:07:50

相關問題