titleForHeader
iOSの背景色を変更したいです。
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"A";
}
このメソッドは、 の titleHeader セクションを表示しUITableView
ます。
デフォルトの背景色は水色です。
これらの背景の黒色を変更したいです。
どのようにできるのか?
titleForHeader
iOSの背景色を変更したいです。
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return @"A";
}
このメソッドは、 の titleHeader セクションを表示しUITableView
ます。
デフォルトの背景色は水色です。
これらの背景の黒色を変更したいです。
どのようにできるのか?
ここでアレックス・レイノルズの回答を見てください
UITableView - セクション ヘッダーの色を変更する
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)] autorelease];
if (section == integerRepresentingYourSectionOfInterest)
[headerView setBackgroundColor:[UIColor redColor]];
else
[headerView setBackgroundColor:[UIColor clearColor]];
return headerView;
}
背景色だけでテキストがない場合
同じ質問に対するDoctorGの回答を見てください
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(10, 3, tableView.bounds.size.width - 10, 18)] autorelease];
label.text = @"Section Header Text Here";
label.textColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.75];
label.backgroundColor = [UIColor clearColor];
[headerView addSubview:label];