【问题标题】:UITableViewHeaderFooterView can't change custom background when loading from nib从笔尖加载时,UITableViewHeaderFooterView 无法更改自定义背景
【发布时间】:2013-09-18 23:49:57
【问题描述】:

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

"设置UITableViewHeaderFooterView的背景颜色已经 已弃用。请改用 contentView.backgroundColor。”

这里是加载我的自定义 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;

}

【问题讨论】:

    标签: ios uitableview


    【解决方案1】:

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

    你也可以考虑做

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

    根本不设置背景颜色。根据this链接,这是Apple的首选方法。

    【讨论】:

    • 将背景颜色设置为默认值,让它像魅力一样工作,谢谢你:D
    猜你喜欢
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 2014-09-27
    • 2013-07-09
    • 2014-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多