ios - 在 IOS 中,选定的 UITableViewCell 的灰色背景颜色来自哪里?

标签 ios ios8 uitableview

正如您在这个小 gif 上看到的,当您在表格 View 中选择一个单元格时,背景颜色变为灰色。

demo 我想以编程方式获得这种颜色。

我已经尝试在我的 UITableViewCell 子类中访问:

self.selectedBackgroundView?.backgroundColor

self.backgroundView?.backgroundColor

但是我得到了蓝色(就像在旧版本的 iOS 中一样)

demo2

我在调试 View 层次结构中查找以找到它,但没有成功。

提前感谢您的帮助!

问候, 埃里克

[编辑] 我在这里尝试的是从我的单元格中获取背景颜色以将其设置在我的单元格内的 subview 上。

最佳答案

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

cell.backgroundColor = [UIColor clearColor];

UIView *bgColorView = [[UIView alloc] init];

// CHoose the color you want to show when cell is selected
bgColorView.backgroundColor = [UIColor colorWithRed:255.0f/255.0f green:250.0f/255.0f blue:240.0f/255.0f alpha:0.1f];

bgColorView.layer.cornerRadius = -17;
bgColorView.layer.masksToBounds = YES;
[cell setSelectedBackgroundView:bgColorView];

关于ios - 在 IOS 中,选定的 UITableViewCell 的灰色背景颜色来自哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29539997/

相关文章:

ios - 三角形 UIView - Swift

ios - UIAlertController 的 UIAlertView show() 行为

ios - 在 iOS 中单击 UIButton 时如何将项目插入 UITableView

ios - UITableView 不调用 cellForRowAtIndexPath

swift - UItableView 无法快速重新加载数据

iOS UIStackView 约束动画隐藏

ios - 点击加号添加应用 Error 500. No Apps showing up

ios - 使用分发临时设置配置文件时未收到推送通知

ios - 在 IOS 7's loadView method of UIViewController, why does UIScreen' 中创建 View 时,主应用程序框架在状态栏下方开始?

ios - UIView 线性动画移动 View