我正在创建 UIItableview。对于第一个单元格,我想要一个带有按钮的用户图像,以允许他更改图像。 (没那么复杂)。
不知何故,我遇到了一个奇怪的问题:当我设置 setMasksToBounds:NO
时,[self.userTable.layer setCornerRadius:20.0];
只是被禁用了。
我附上了带有输出示例的代码:
//Initiate UserTable
//[self.userTable setClipsToBounds:NO];//from the documentation this line is set by default
[self.userTable.layer setCornerRadius:20.0];
[self.view addSubview:self.userTable];
稍后在 cellForRowAtIndexPath:
中我添加:
[myCellView.contentView addSubview:photo]; //My photo is UImageview
如果我取消注释行 [self.userTable setClipsToBounds:NO]
我得到:
但是我的角不再圆了...... 我阅读了以下问题 this和 this还是想不通? 有人遇到过这个问题并且可以提供不会强制我更改所有代码的修复程序吗?以及这两个选项如何相互关联? 非常感谢。
最佳答案
调用 setCornerRadius
将 mask 应用到您的 CALayer,然后用于 mask 边界并创建圆角效果。
通过调用 setMasksToBounds:NO
,您将禁用圆角机制。
简而言之,您不能同时拥有这两种方式。
考虑让表格 View 中的那一行更高,或者使用自定义 View 而不是标准的 UITableViewCell
。
关于ios - 为什么 setClipsToBounds :NO disables setCornerRadius: for UItableview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23186664/