正如您在这个小 gif 上看到的,当您在表格 View 中选择一个单元格时,背景颜色变为灰色。
我想以编程方式获得这种颜色。
我已经尝试在我的 UITableViewCell 子类中访问:
self.selectedBackgroundView?.backgroundColor
和
self.backgroundView?.backgroundColor
但是我得到了蓝色(就像在旧版本的 iOS 中一样)
我在调试 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/