// UITableView 継承後 デリゲートにて下記メソッドを追加する。
– (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *sectionView = [[UIView alloc] init];
if (section == 0) {
// セクションナンバーが0 の場合は
sectionView.backgroundColor = [UIColor whiteColor];
return sectionView;
}else{
// UIView を戻り値にて返すとセクションに反映される。
UIView *sectionView = [[UIView alloc] init];
sectionView.backgroundColor = [UIColor whiteColor];
sectionView.frame = CGRectMake(0.0f, 0.0f, 320.0f, 44.0f);
// UIView にラベルを追加する。
UILabel *sectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
// テキストの色を変更したり・・・
sectionLabel.textColor = [UIColor whiteColor];
// 背景の色を変更したり・・・
sectionLabel.backgroundColor = [UIColor whiteColor];
sectionLabel.text = @”test”;
// シャドウカラーを設定することももちろんできます。
sectionLabel.shadowColor = [UIColor whiteColor];
sectionLabel.shadowOffset = CGSizeMake(0, 0.3);
// フォント変更ももちろん可能
sectionLabel.font = [UIFont systemFontOfSize:24];
// ビューにセットして
[sectionView addSubview:sectionLabel];
// ビューを戻り値で返すとセクションに反映されます。
}
return sectionView;
}
// UITableView 継承後 デリゲートにて下記メソッドを追加する。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *sectionView = [[UIView alloc] init];
if (section == 0) {
// セクションナンバーが0 の場合は
sectionView.backgroundColor = [UIColor whiteColor];
return sectionView;
}else{
// UIView を戻り値にて返すとセクションに反映される。
UIView *sectionView = [[UIView alloc] init];
sectionView.backgroundColor = [UIColor whiteColor];
sectionView.frame = CGRectMake(0.0f, 0.0f, 320.0f, 44.0f);
// UIView にラベルを追加する。
UILabel *sectionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
// テキストの色を変更したり・・・
sectionLabel.textColor = [UIColor whiteColor];
// 背景の色を変更したり・・・
sectionLabel.backgroundColor = [UIColor whiteColor];
sectionLabel.text = @"test";
// シャドウカラーを設定することももちろんできます。
sectionLabel.shadowColor = [UIColor whiteColor];
sectionLabel.shadowOffset = CGSizeMake(0, 0.3);
// フォント変更ももちろん可能
sectionLabel.font = [UIFont systemFontOfSize:24];
// ビューにセットして
[sectionView addSubview:sectionLabel];
// ビューを戻り値で返すとセクションに反映されます。
}
return sectionView;
}
