如何更改背景选定颜色故事板静态单元格 [英] How to change background selected color storyboard static cells

查看:27
本文介绍了如何更改背景选定颜色故事板静态单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带故事板的应用.在一个场景中,我有一个包含静态单元格内容的 tableview.是否可以将选定的背景颜色更改为默认选项(蓝色和灰色)之外的另一种颜色?

I have an app with storyboard. In one scene I have a tableview with statics cell content. Is possible to change the background selected color to another color out of the default options (blue and gray)?

我知道是否可以在 forRowAtIndexPath 中更改单元格背景颜色,但在这种情况下,我没有来自 tableview 的任何数据源函数.我确信可以从 IB 或其他我可以修改的函数中...

I know If I can change cell background color in forRowAtIndexPath but in this case I haven't any datasource function from tableview. I'm sure that it is possible from IB or another function that I can modify...

提前致谢!

推荐答案

我遇到了同样的问题.解决方案分为两部分:

I had the same problem. The solution has two parts:

1) 获取单元格,查看this.2) 改变背景颜色:你必须创建一个带有你需要的背景颜色的 UIView 并将其设置为单元格的 selectedBackgroundView

1) getting the cells, look at this. 2) changing the background color: you must create a UIView with the background color you need and set it as the selectedBackgroundView of the cell

例如,我在 uitableviewcontroller 的 viewDidLoad 中使用了这段代码:

For instance, I used this code in the viewDidLoad of the uitableviewcontroller:

UIView *backgroundSelectedCell = [[UIView alloc] init];
[backgroundSelectedCell setBackgroundColor:[UIColor colorWithRed:130/256.0 green:169/256.0 blue:171/256.0 alpha:1.0]];

for (int section = 0; section < [self.tableView numberOfSections]; section++)
    for (int row = 0; row < [self.tableView numberOfRowsInSection:section]; row++)
    {
        NSIndexPath* cellPath = [NSIndexPath indexPathForRow:row inSection:section];
        UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:cellPath];

        [cell setSelectedBackgroundView:backgroundSelectedCell];
    }  

这篇关于如何更改背景选定颜色故事板静态单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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