clifgray
clifgray

Reputation: 4419

Making a TableViewCell Section Footer Transparent

I am trying to make a section footer of a UITableViewCell transparent and this is what I am doing right now:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIColor *background = [UIColor clearColor];

    UIImageView *imageView = [[UIImageView alloc] initWithImage:(UIImage *)background];
    imageView.frame = CGRectMake(10,10,1,30);

    return imageView;
}

But I am getting a problem from casting background to a UIImage. Is this possible in this way, is there a better way to cast it or am I simply going about this wrong? I am basically using the footer as a way to create a clear spacer between cells. Need some guidance on this.

Upvotes: 1

Views: 713

Answers (2)

Jim Tierney
Jim Tierney

Reputation: 4105

This code will add clear footer to your section, where you can set the desired height to whatever you need. Below it has been set to 30, to match your code in the question.

-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

    UIView *footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 30)];
    footerView.backgroundColor = [UIColor clearColor];

    return footerView;
}

Upvotes: 1

Kumar KL
Kumar KL

Reputation: 15335

Instead of type casting the colour into the UIImage, use the backgroundColor property :

Try this :

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,1,30)];
 imageView.backgroundColor  = [UIColor clearColor];

Upvotes: 1

Related Questions