- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我已经阅读并尝试了一些在 StackOverflow 上找到的答案。我也阅读并尝试了博客中的一些东西,但似乎没有任何东西可以实现我正在寻找的东西。
我创建了一个 UIView
并将其背景颜色设置为我想要的 UITableViewCell
选择颜色 (而不是标准的蓝色或灰色选择颜色) .我将这个 UIView
添加到我的单元格的 selectedBackgroundView
并且这工作正常,我的单元格在用户选择时更改为所需的颜色。
此方法在 Plain UITableViews
上效果很好;在分组上不太好。在分组的 UITableView
上,第一个和最后一个单元格不符合剪辑/ mask 边界,如下面的屏幕截图所示。
我知道没有办法仅将左上角和右上角四舍五入。
我想严格地通过代码来做到这一点,没有图像。
有没有人知道一个不错的小工作来改变 UITableViewCell
的 selectedBackgroundView
颜色只使用 UIView
而不是图像并使第一个和最后一个单元格符合圆角边界?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = @"Cell";
WCSBadgedCell * cell = [[WCSBadgedCell alloc] initWithStyle:UITableViewCellStyleSubtitle andBadgeStyle:0 reuseIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[WCSBadgedCell alloc] initWithStyle:UITableViewCellStyleDefault andBadgeStyle:0 reuseIdentifier:CellIdentifier];
}
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:DARKBROWN];
[bgColorView setClipsToBounds: YES];
[cell.layer setMasksToBounds:YES];
[cell setSelectedBackgroundView:bgColorView];
[cell.textLabel setText: @"Testing a Cell"];
return cell;
}
我接受了 CodaFis answer因为他添加了一条评论,指出了一个非常好的(但冗长) 解决方案。我不得不做很多修改,但最后,我现在有了我需要的 selectedBackgroundView,它位于第一个和最后一个单元格的拐角处,再次感谢!
最佳答案
由于单元格的复杂性,我假设您正在使用 UITableViewCell 子类。这就是我一直在做的:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]))
{
self.clipsToBounds = YES;
UIView* bgView = [[UIView alloc] init];
bgView.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.25f];
self.selectedBackgroundView = bgView;
//other code
}
return self;
}
这会在单元格上产生一种深灰色覆盖层,而不是所需的图像!
在你的例子中,你选择的单元格的确切颜色(多亏了方便的花花公子数字颜色计)将是
[UIColor colorWithRed:106.0f/255.0f green:51.0f/255.0f blue:6.0f/255.0f alpha:1.0f];
白色的文字是
- (void)setSelected:(BOOL)sel animated:(BOOL)animated
{
[super setSelected:sel animated:animated];
if (sel)
{
self.textLabel.textColor = [UIColor whiteColor];
}
else
{
self.textLabel.textColor = [UIColor colorWithRed:(105.f/255.f) green:(50.f/255.f) blue:(6.f/255.f) alpha:1.f];
}
}
关于ios - 关于如何将 UIView 屏蔽为 UITableViewCell selectedBackgroundView 的明确答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10219560/
我的 UITableViewCells 都是预定义的“字幕”样式。我想将所选单元格的背景图像设置为另一张图片。我尝试了各种方法来实现这个,在 stackoverflow 上讨论的所有方法似乎都失败了。
我正在尝试为我的 collectionView 单元格创建自定义 selectedBackgroundView。我将 UIView 子类化,这是我的 drawRect 实现: override fun
我有一个带有自定义 selectedBackgroundView 的自定义 UITableViewCell。 selectedBackgroundView 显示时是否有委托(delegate)方法?例
想象一下您有一个 UICollectionView 的场景,并且您希望在每个单元格中有一个按钮填充整个单元格,以便您可以响应各种触摸事件来处理高亮外观。例如,当用户按下按钮时,您想要更改按钮的背景颜色
我设置了自定义UITableViewCell有多个标签和一个图像,我(终于)让它看起来像我想要的样子。 但是,我似乎无法弄清楚如何让选择看起来像我想要的样子。我已经实现了setSelected方法,它
我需要为 UITableViewCell 的 selectedBackgroundView 更改 alpha。所以我做了以下事情: UITableViewCell *cell = [tableView
我有一个 UICollectionView。一些单元格内部带有白色背景颜色。我已将 selectedBackgroundView 设置为基本的紫色 View 。 我的 CollectionView 有
我正在为 UITableViewCell 子类使用自定义 backgroundView 和 selectedBackgroundView。这些单元格位于分组表中,因此我根据 cellForRowAtI
我显示了一个表格单元格,其中显示了用户图像、名称和一些文本。用户的图像为 50x50,但我想要在其周围有边框,因此我将 View 设置为图像居中并将框架设置为 52x52,然后将该 View 的背景颜
我在 iOS7 中使用 UITableVeiw 和静态单元格。在我将 Storyboard转换为使用自动布局之前,表格 View 看起来像这样。 我正在使用 tableviewcell 的“背景 Vi
我有一个 UITableView,在 cellForRowAtIndexPath 方法中我设置了单元格的 SelectedBackgroundView 属性。当我手动点击单元格时,背景 View 会正
我正在使用 TableView 来显示树结构。每个单元格对应一个用户可以展开或折叠的节点。每个节点的级别通过在单元格的前缘具有越来越大的缩进来可视化。这些缩进是使用 layoutMargins 设置的
使用 UITableView Style Grouped 后,使用带有自定义颜色的 selectedBackgroundView 时会出现问题。 它在 UITableViewCell 之外绘制。是否可
注意:在将我的问题标记为重复之前,请仔细阅读。重复我按下并按住表格 View 单元格的问题状态的步骤,这意味着我从不“选择”该单元格(进一步证明 didSelectRowAtIndexPath 永远不
我知道如果我想改变 UITableViewCell 的高亮,我需要运行下面的代码: self.selectedBackgroundView = UIView(frame: self.frame) se
致力于将 iOS6 应用程序转换为 iOS7,他们正在使用它来设置分组 TableView 样式。 cell.backgroundView = aView; cell.selected
我已经阅读并尝试了一些在 StackOverflow 上找到的答案。我也阅读并尝试了博客中的一些东西,但似乎没有任何东西可以实现我正在寻找的东西。 我创建了一个 UIView 并将其背景颜色设置为我想
我有一个 UITableView 呈现自定义类 DrawerTableCell 的单元格,它是这样声明的: class DrawerTableCell: UITableViewCell { @
我刚刚开始实现多选 UICollectionView。下面会被认为是“安全”代码吗(因为我假设有一些原因它被称为 BackgroundView 而不是 AccessoryView 或类似的)?我想节省
在以下任何方法中设置 backgroundView 和 selectedBackgroundView 似乎都不起作用。 UIView * bSg = [[UIView alloc] init]; UI
我是一名优秀的程序员,十分优秀!