从nib加载时,UITableViewHeaderFooterView无法更改自定义背景 [英] UITableViewHeaderFooterView can't change custom background when loading from nib

查看:140
本文介绍了从nib加载时,UITableViewHeaderFooterView无法更改自定义背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个自定义UITableViewHeaderFooterView并成功从nib加载到我的UITableView但总是收到此消息

I've created a custom UITableViewHeaderFooterView and successfully load from nib into my UITableView but always get this message


设置背景颜色在UITableViewHeaderFooterView已被弃用
。请改用contentView.backgroundColor。

"Setting the background color on UITableViewHeaderFooterView has been deprecated. Please use contentView.backgroundColor instead."

这里是加载我的自定义UITableViewHeaderFooterView的代码:

Here the code for loading my custom UITableViewHeaderFooterView:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
   KTHeaderFooterViewIphone customHeaderIphone* = [[[NSBundle mainBundle] loadNibNamed:@"KTHeaderFooterViewIphone" owner:self options:nil] objectAtIndex:0];
    customHeaderIphone.tintColor = [UIColor whiteColor];  // this code worked, but the message above always show
    customHeaderIphone.contentView.backgroundColor = [UIColor redColor];  // this code doesn't work, nothing's happened
    customHeaderIphone.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"customHeader.png"]];  // this code doesn't work too, I can't change custom background image
    return customHeaderIphone;

}

推荐答案

您是否在笔尖的页脚视图中设置了背景颜色属性?如果是这样,请将其设置为默认。

Did you set the "Background Color" attribute on the footer view in your nib? If so, set that to "Default".

您也可以考虑这样做

customHeaderIphone.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"customHeader"]];

并且根本没有设置backgroundColor。这是Apple根据链接。

and not setting the backgroundColor at all. This is Apple's preferred method according to this link.

这篇关于从nib加载时,UITableViewHeaderFooterView无法更改自定义背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆