2012-02-21 10 views
0

グループスタイルを使用してUITableViewを作成しました。私は自分のテーブルに1つのグループしか持っていません。ここで 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を使用しているので、私はすべてのautorealeaseを削除しました – xcoderookie

+0

それは後にうまく動作したことをうまく希望します。あなたの質問への解決策を見つけた場合は、チェックマークにチェックを入れてください! – rinzler