OGeek|极客世界-中国程序员成长平台

标题: ios - 使用 UIColor 平铺图像作为 View 的背景不适用于cornerRadius [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:06
标题: ios - 使用 UIColor 平铺图像作为 View 的背景不适用于cornerRadius

我使用 UIColor colorWithPatternImage 来获得平铺颜色。我将此设置为我的 View 的背景。在此之后,对 view.layer.cornerRadius 的任何更改都不会产生任何影响:它不会更改角半径。我还尝试在我的 View 中添加另一个 subview ,将其设置为图案的背景颜色并在我的 View 上使用cornerRadius 无济于事。

如何解决此问题?

感谢您的宝贵时间。



Best Answer-推荐答案


将 View 的 clipsToBounds 设置为 YES,它应该可以工作。我有同样的问题。

这是我的片段:

self.leftPanelView.layer.cornerRadius = 10;
self.leftPanelView.clipsToBounds = YES;
self.leftPanelView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed"linePattern_gray.png"]];

将 linePattern_gray.png 显示为带有漂亮圆角图案的背景。

关于ios - 使用 UIColor 平铺图像作为 View 的背景不适用于cornerRadius,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5533258/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4