各セクションのヘッダーをカスタマイズしたいUITableView
。これまで実装してきた
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
このUITabelViewDelegate
メソッド。私がやりたいのは、各セクションの現在のヘッダーを取得し、UILabel
サブビューとして追加することです。
今のところ、それを達成できていません。デフォルトのセクションヘッダーを取得できるものが見つからなかったからです。最初の質問は、デフォルトのセクションヘッダーを取得する方法はありますか?
それが不可能な場合は、コンテナ ビューを作成する必要がありますがUIView
、今回はデフォルトの背景色、影の色などを設定する必要があります。セクションのヘッダーを注意深く見ると、すでにカスタマイズされているからです。
各セクション ヘッダーのデフォルト値を取得するにはどうすればよいですか?
ベストアンサー1
これを試すことができます:
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)];
/* Create custom view to display section header... */
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, tableView.frame.size.width, 18)];
[label setFont:[UIFont boldSystemFontOfSize:12]];
NSString *string =[list objectAtIndex:section];
/* Section header is in 0th index... */
[label setText:string];
[view addSubview:label];
[view setBackgroundColor:[UIColor colorWithRed:166/255.0 green:177/255.0 blue:186/255.0 alpha:1.0]]; //your background color...
return view;
}