当前位置 博文首页 > xixi:改变 UITableViewHeaderFooterView 的背景颜色
今天遇到一个比较坑爹的问题! 没有用过这个玩意!不知道怎样在 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section? 这个代理方法里面? 改变sectionHeader 背景颜色.
尝试了设置很多 ,还是不行!最后还是设置? backgroundView 搞定!
headerView.backgroundView = [[UIImageView alloc] initWithImage:[PublicFunctions imageWithColor:[UIColor whiteColor] size:CGSizeMake(511, 58) alpha:0.4]];
要设置一张图片上去 才行
附上 用代码 初始化一张纯色图片
这样就搞定了
+ (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size alpha:(float)alpha
{
@autoreleasepool {
CGRect rect = CGRectMake(0, 0, size.width, size.height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetAlpha(context, alpha);
CGContextSetFillColorWithColor(context,color.CGColor);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
}