【问题标题】:How to change the background of a UITableView in Xcode 5 with interface builder [closed]如何使用界面生成器在 Xcode 5 中更改 UITableView 的背景 [关闭]
【发布时间】:2014-06-28 19:51:49
【问题描述】:

我正在尝试将我的 UITableView 从全白更改为黑色背景,但是如何在 Interface Builder 中实现这一点?

【问题讨论】:

    标签: ios uitableview ios7 xcode5


    【解决方案1】:

    根据苹果...

    ... 在 iOS 7 中,单元格默认为白色背景;在早期版本的 iOS 中,单元格继承了封闭表格视图的背景颜色。如果要更改单元格的背景颜色,请在表格视图委托的 tableView:willDisplayCell:forRowAtIndexPath: 方法中进行。

    所以用代码来做,很简单...

    首先,将其添加到 tableViewController 中的 viewDidLoad:

        UIView *patternView = [[UIView alloc] initWithFrame:self.tableView.frame];
            patternView.backgroundColor = [UIColor blackColor];
            patternView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
            self.tableView.backgroundView = patternView;
    

    然后在你的 cellForRowAtIndexPath 中,添加这个:

    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor whiteColor];
    

    (textLabel 可以是你想要的任何颜色)

    另请参考:UITableViewCell show white background and cannot be modified on iOS7

    在 Interface Builder 中执行此操作时似乎存在错误。

    【讨论】:

    • 我想是时候学习如何在没有界面生成器的情况下编写代码了......
    • 嗯,这取决于你想定制多少东西。 IB 可以进行少量定制,但代码有更多具体的选项。您是否尝试将我的代码添加到您的项目中?
    • 是的,我试过了。它对我有用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多