UITableViewHeaderFooterView: Unable to change background color

前端 未结 20 2256
误落风尘
误落风尘 2020-12-23 08:38

I\'m trying to change the background color of UITableViewHeaderFooterView. Although the view is appearing, the background color remains the default color. I\'m getting a log

20条回答
  •  我在风中等你
    2020-12-23 09:19

    In iOS 7 contentView.backgroundColor worked for me, tintColor did not.

       headerView.contentView.backgroundColor = [UIColor blackColor];
    

    Though clearColor did not work for me, the solution I found is to set backgroundView property to transparent image. Maybe it will help someone:

    UIGraphicsBeginImageContextWithOptions(CGSizeMake(1, 1), NO, 0.0);
    UIImage *blank = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    headerView.backgroundView = [[UIImageView alloc] initWithImage:blank];
    

提交回复
热议问题