私はかなり単純な質問をしています(そう願っています)。UITableview のセクション ヘッダーの色をデフォルトの青から透明な黒に変更するにはどうすればよいですか? 前もって感謝します。
14684 次
3 に答える
21
これは古い質問ですが、回答を更新する必要があると思います。
この方法では、独自のカスタム ビューを定義する必要はありません。
iOS 6 以降では、背景色とテキスト色を簡単に変更できます。
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)ビュー forSection:(NSInteger)セクションデリゲート メソッド。
例えば:
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section { // 背景色 view.tintColor = [UIColor blackColor]; // テキストの色 UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view; [header.textLabel setTextColor:[UIColor whiteColor]]; // 背景色を設定する別の方法 // 注: 元のヘッダーのグラデーション効果は保持されません // header.contentView.backgroundColor = [UIColor blackColor]; }
私の投稿から引用: https://happyteamlabs.com/blog/ios-how-to-customize-table-view-header-and-footer-colors/
于 2013-10-04T05:11:47.183 に答える
18
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 だと思いますが、好きなように設定できます。これがあなたの質問の意味ですか?お役に立てれば。
于 2010-03-05T22:00:11.447 に答える
0
- (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;
}
于 2013-07-23T06:55:02.530 に答える