简体   繁体   English

设置背景色会使表格单元格变形

[英]Setting background color distort the Table cell

I have a grouped table view on one of my view. 我在其中一个视图上有一个分组表视图。 And inside the cellForRowAtIndexPath delegator method I have set background color for each table cell as follows. 在cellForRowAtIndexPath委托方法内部,我为每个表格单元设置了背景颜色,如下所示。

UIColor *color = [UIColor colorWithRed:221.0/255 green:241.0/255 blue:249.0/255 alpha:1.0];
[cell.contentView setBackgroundColor:color];

Background color set without any problem. 设置背景色没有任何问题。 But problem occur in top and bottom cells. 但是问题出现在顶部和底部单元格中。 In top and bottom cells have curved edges. 在顶部和底部的单元格具有弯曲的边缘。 But when I add the background color it distort the edges. 但是,当我添加背景色时,它会使边缘变形。 I have uploaded a print screen in such window.You can see the issue occure in the bottom cell where i have set the background color. 我已经在这样的窗口中上传了打印屏幕。您可以在我设置背景颜色的底部单元格中看到问题。 Can some one please tell me how to solve this problem. 有人可以告诉我如何解决这个问题。 在此处输入图片说明

Use cell.backgroundColor = [UIColor redColor]; 使用cell.backgroundColor = [UIColor redColor];

not

[cell.contentView setBackgroundColor:color];

A UITableViewCell is a more complex object than an object with a contentView propretry. 与具有contentView属性的对象相比,UITableViewCell是一个更复杂的对象。 You can find more about cell in UITableViewCell Class Reference 您可以在UITableViewCell类参考中找到有关单元的更多信息。

将单元格的clipsToBounds属性设置为YES,这将使其遵循舍入的单元格边界。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM