gpt4 book ai didi

ios - 使用自定义选择颜色和边框创建分组的 UITableviewCell

转载 作者:行者123 更新时间:2023-11-29 11:15:38 29 4
gpt4 key购买 nike

我目前正在编写一个在分组 TableView 中使用不同选择颜色的应用程序。就边界而言,这非常有效。我可以使用这篇文章中的代码更改选择颜色: How to customize the background/border colors of a grouped table view cell?

但是 我还想在 Apple 使用的单元格周围添加漂亮的边框。如何使用此边框?

http://www.mediafire.com/?x2gxbkjqu4d2zto

这是创建背景的代码 - 大部分是从上面的帖子复制的: http://www.mediafire.com/?kltwlni1mf4t7ks

这就是我使用它的方式:

NSIndexPath * indexPath = [[[NSIndexPath alloc] initWithIndex:0] indexPathByAddingIndex:1];
CGRect frame = [[self tableView] rectForRowAtIndexPath:indexPath];
TLCustomCellBackgroundView * selectedBackgroundView = [[TLCustomCellBackgroundView alloc] initWithFrame:frame andColor:[UIColor redColor]];
[selectedBackgroundView setPosition:CustomCellBackgroundViewPositionBottom];
[[[self tableView] cellForRowAtIndexPath:indexPath] setSelectedBackgroundView:selectedBackgroundView];

如您所见,除了第二个单元格周围的灰色边框外,我几乎可以正常工作。

最佳答案

在 cellForRowAtIndexPath 中,您可以为每一行/部分设置边框(分隔符)。

 if(indexPath.row == 1)
[tableView setSeparatorColor:[UIColor redColor]];

if(indexPath.section == 2)
[tableView setSeparatorColor:[UIColor greenColor]];

请记住为您想要的每一行/部分设置/重置它。

如果你想在你的红色单元格周围添加灰色边框,那就是

if(indexPath.section == 0 && indexPath.row == 1){
//assuming this is the correct index)
[tableView.separatorColor = [UIColor colorWithRed:0.67 green:0.67 blue:0.67 alpha:1];
}
else
{
[tableView.separatorColor = [UIColor yourChosenDefaultColor]];
}

您实际上需要在您的 cellForRowAtIndexPath 中使用它,否则您将为整个 TableView 设置边框(也许这就是您想要做的)

关于ios - 使用自定义选择颜色和边框创建分组的 UITableviewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9602657/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com