質問

非常に単純な単純な質問があります(そうであってほしいと思います)。UITableviewのセクションヘッダーの色をデフォルトの青から黒の透明に変更するにはどうすればよいですか?前もって感謝します。

役に立ちましたか?

解決

このメソッドを UITableViewDelegate プロトコルに実装する必要があります。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

ここにリンクがあります ドキュメンテーション

...そして次のようなことを行います(独自の色でサブ):

UIView *sectionView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 22)] autorelease];
[sectionView setBackgroundColor:[UIColor blackColor]];
return sectionView;

セクション整数を使用して、色などを交互に変更することもできます。セクションのデフォルトの高さは 22 だと思いますが、お好みに合わせて変更できます。これがあなたの質問の意味ですか?お役に立てれば。

他のヒント

この古い質問ですが、私は答えを更新する必要があると考えます。

この方法では、独自のカスタムビューを定義する必要ありません。
iOSの6とアップでは、あなたは簡単に
を定義することで、背景色と文字色を変更することができます

- (void)tableView:(UITableView *)tableView 
        willDisplayHeaderView:(UIView *)view 
        forSection:(NSInteger)section
デリゲートメソッド。

例えば、

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
    // Background color
    view.tintColor = [UIColor blackColor];

    // Text Color
    UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
    [header.textLabel setTextColor:[UIColor whiteColor]];

    // Another way to set the background color
    // Note: does not preserve gradient effect of original header
    // header.contentView.backgroundColor = [UIColor blackColor];
}

ここに私のポストから撮影: https://happyteamlabs.com/ブログ/ IOS-方法・ツー・カスタマイズ・テーブル・ビュー・ヘッダーとフッター--色/

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
   {
     UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,tableView.bounds.size.width, 30)];
     if (section == 0)
     [headerView setBackgroundColor:[UIColor redColor]];
     else 
     [headerView setBackgroundColor:[UIColor clearColor]];
     return headerView;
   }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top