简体   繁体   English

如何更改具有多个部分的表格单元格的背景颜色?

[英]How can i change the background color of a table cell with multiple sections?

I have a table view with multiple sections and don't know how to change the background color when i touch that row.我有一个包含多个部分的表格视图,当我触摸该行时不知道如何更改背景颜色。

I've found this link about table cells but it is addressed to tables with only one section:我找到了这个关于表格单元格的链接,但它只针对只有一个部分的表格:

changing cell background on click on cell in iphone . 在 iphone 中单击单元格时更改单元格背景

cell.selectedBackgroundView = [[ UIView alloc] init];
[cell.selectedBackgroundView setBackgroundColor:[UIColor purpleColor]];

if i use the code from this link, cells that are rounded (the first and last in every section) will have a rectangle on finger over which doesn't look good.如果我使用此链接中的代码,则被舍入的单元格(每个部分中的第一个和最后一个)将在手指上有一个看起来不太好的矩形。

How can i make this rectangle curved around the edges for the first and last row in every section?我怎样才能使这个矩形围绕每个部分的第一行和最后一行的边缘弯曲?

How about using some quartz core.使用一些石英芯怎么样。 you can make any view round rect using view.layer.cornerRadius = 5.0;您可以使用view.layer.cornerRadius = 5.0;

make sure to import header确保导入 header

#import <QuartzCore/QuartzCore.h>

EDIT编辑

Try to create custom cell then and set a UIView for background view property and change color as you wish.然后尝试创建自定义单元格并为背景视图属性设置 UIView 并根据需要更改颜色。 That way it will work.这样它就会起作用。

UPDATE更新

Yes you are right.是的你是对的。 There is tutorial on internet for grouped tableView's let me google it for you.互联网上有分组 tableView 的教程,让我为您搜索它。 Use this post it has everything you need http://pessoal.org/blog/2009/02/25/customizing-the-background-border-colors-of-a-uitableview/使用这篇文章它有你需要的一切http://pessoal.org/blog/2009/02/25/customizing-the-background-border-colors-of-a-uitableview/

here is another stackoverflow post for the same这是另一个相同的stackoverflow帖子

How to customize the background/border colors of a grouped table view cell? 如何自定义分组表格视图单元格的背景/边框 colors?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改选定的自定义表格视图单元格的药水的背景颜色 - How to change the background color of a potion of a selected custom table view cell 如何为带有部分的tableview单元格设置备用背景色 - How to set alternate background color for tableview cell with sections 如何在iphone上的UITableView中设置单元格的背景颜色? - How can I set the background color of a cell in UITableView on iphone? 表格细胞的背景颜色 - Background color of table cell 无法更改iOS 7(iPad)上静态表格视图单元格的背景颜色 - Unable to change background color of static table view cell on iOS 7 (iPad) 用于更改标签背景颜色的表格单元格按钮操作 - Table Cell Button action to change the label background color 如何在UITableviewCell中点击更改UIButton的背景颜色? - How can i change background color of UIButton on click in UITableviewCell? 如何动态更改UITableViewCell的背景颜色? - How can I change the background color of a UITableViewCell dynamically? 如何更改特定UIViewCollectionCell的背景颜色? - How can I change the background color of an specific UIViewCollectionCell? 当UITableView正在编辑并且可以移动时,则如何更改位于单元格右侧的移动按钮的背景颜色 - When UITableView is editing and can be moved , then how to change the background color of the move button which is in right side of the cell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM