zoukankan      html  css  js  c++  java
  • UITableViewHeaderFooterView can't change custom background when loading from nib

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

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

    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;

    }


    answer:

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

    Also you may want to consider doing

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

    and not setting the backgroundColor at all. This is Apple's preferred method according tohttps://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewHeaderFooterView_class/Reference/Reference.html#//apple_ref/occ/instp/UITableViewHeaderFooterView/backgroundView


    from:http://stackoverflow.com/questions/18800743/uitableviewheaderfooterview-cant-change-custom-background-when-loading-from-nib


  • 相关阅读:
    terminal
    变量提升、函数提升
    ssh传输文件
    mocha测试框架
    npm-run 自动化
    webpack
    浅析babel
    构建工具gulp
    C++中TRACE宏及assert()函数的使用
    memcpy函数-C语言
  • 原文地址:https://www.cnblogs.com/zsw-1993/p/4879662.html
Copyright © 2011-2022 走看看