ios - 为什么 setClipsToBounds :NO disables setCornerRadius: for UItableview?

标签 ios uitableview calayer

我正在创建 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

enter image description here

如果我取消注释行 [self.userTable setClipsToBounds:NO] 我得到: enter image description here

但是我的角不再圆了...... 我阅读了以下问题 thisthis还是想不通? 有人遇到过这个问题并且可以提供不会强制我更改所有代码的修复程序吗?以及这两个选项如何相互关联? 非常感谢。

最佳答案

调用 setCornerRadius 将 mask 应用到您的 CALayer,然后用于 mask 边界并创建圆角效果。 通过调用 setMasksToBounds:NO,您将禁用圆角机制。

简而言之,您不能同时拥有这两种方式。

考虑让表格 View 中的那一行更高,或者使用自定义 View 而不是标准的 UITableViewCell

关于ios - 为什么 setClipsToBounds :NO disables setCornerRadius: for UItableview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23186664/

相关文章:

ios - 在 GoogleMapSDK 上放置标记

ios - UIView 对象可以充当 UITableView 对象吗?

ios - 创建带圆角的 View (四分之一圆)

objective-c - 如何在 iOS 中计算 SHA-2(最好是 SHA 256 或 SHA 512)哈希?

ios - 游戏中心验证问题

ios - 未调用 TableViewCell 内的 UICollectionView

ios - 在整个屏幕上弹出 UITableViewCell subview

ios - 问题理解 CALayer 几何。需要帮助

objective-c - 如何在 Mac OS X 上将 CALayer 添加到 NSView

ios - UIPageViewController委托(delegate)方法类似于scrollViewDidScroll :(UIScrollview*)scrollview