好像仅适用于:tableview的style有plain和group之分,如果用plain,写上下面的代码,则可以出现下面效果。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
if(section == 0){
UIView *headerView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
label.backgroundColor = [UIColor colorWithRed:137/255.0 green:154/255.0 blue:168/255.0 alpha:0.8];
label.font = [UIFont boldSystemFontOfSize:14];
//label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.8];
label.textAlignment = UITextAlignmentLeft;
label.textColor = [UIColor whiteColor];
label.text = [NSString stringWithFormat:@"当前地区:%@",appDelegate.hotTrend.region.name];
[headerView addSubview:label];
[label release];
return headerView;
}else{
return nil;
}
}