简体   繁体   中英

Using UIColor tiled images as the background of a view doesn't work with cornerRadius

I have used UIColor colorWithPatternImage to get a tiled color. I set this as the background of my view. After this, any changes to view.layer.cornerRadius do not have any affect: it doesn't change the corner radius. I have also tried adding another subview to my view, setting that's background color to the pattern and using cornerRadius on my view to no avail.

How can I fix this behaviour?

Thanks for your time.

Set the clipsToBounds of the view to YES and it should work. I had the same issue.

Here is my snippet:

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

which shows the linePattern_gray.png as the background patterned with a nice rounded corner.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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