Thursday, April 26, 2012

thumbnail

UITableView Custom Header With Background and Header Text


- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{
    UIView *customView = [[[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 320.0, 22.0)] autorelease];
    customView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bar.png"]];;
    
    UILabel *headerLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
    headerLabel.backgroundColor = [UIColor clearColor];
    headerLabel.opaque = NO;
    headerLabel.textColor = [UIColor whiteColor];
    headerLabel.font = [UIFont boldSystemFontOfSize:18];
    headerLabel.shadowOffset = CGSizeMake(0.0f, 1.0f);
    headerLabel.shadowColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
    headerLabel.frame = CGRectMake(11,-11, 320.0, 44.0);
    headerLabel.textAlignment = UITextAlignmentLeft;
    
    if(section == 0) {
        headerLabel.text@"First Section Header";
    }else if(section == 1) {
        headerLabel.text@"Second Section Header";
    }else if(section == 2) {
        headerLabel.text@"Third Section Header";
    }else {
        headerLabel.text@"";
    }

    [customView addSubview:headerLabel];
    return customView;
}

Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments

comments

About me

simple one.