使用viewForHeaderInSection
方法。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UILabel *label1 = [[UILabel alloc] init];
label1.frame = CGRectMake(0, 0, 190, 20);
label1.textColor = [UIColor blackColor];
// label1.font = [UIFont fontWithName:@"Helvetica Bold" size:16];
[label1 setFont:[UIFont fontWithName:@"Arial-BoldMT" size:14]];
label1.textAlignment = UITextAlignmentCenter;
label1.text =[NSString stringWithFormat:@"Title %d",section];
// If your title are inside an Array then Use Below Code
label1.text =[titleArray objectAtindex:section];
label1.textColor = [UIColor whiteColor];
label1.backgroundColor = [UIColor clearColor];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
[view addSubview:label1];
view.backgroundColor = [UIColor orangeColor];
return view;
}
如果您想使用,请titleForHeaderInSection
使用以下代码。
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [NSString stringWithFormat:@"Title %d",section];
// If your title are inside an Array then Use Below Code
return [titleArray objectAtindex:section];
}