开发者

Background Color adjustment to rounded corners view

开发者 https://www.devze.com 2023-04-12 04:17 出处:网络
I have a view that I did for myself and rounded its corners. And when I try to adjust the backgroundColor property I end up with the background color there as a square, disrespec开发者_Go百科ting my r

I have a view that I did for myself and rounded its corners. And when I try to adjust the backgroundColor property I end up with the background color there as a square, disrespec开发者_Go百科ting my rounded corners.

Is there a solution?

Thanks in advance.


Call [[yourView layer] setMasksToBounds:YES]; and it should clip the rounded corners.

I'm pretty sure you won't even need the setClipsToBounds.

More on the subject of layers: http://www.cimgf.com/2010/01/28/fun-with-uibuttons-and-core-animation-layers/


Try this code once.

self.settingsView.frame=CGRectMake(18, 73, 284, 210);
[self.settingsView setBackgroundColor:[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.1]];
[self.settingsView setClipsToBounds:YES];
//Enable maskstobound so that corner radius would work.
[self.settingsView.layer setMasksToBounds:YES];
//Set the corner radius
[self.settingsView.layer setCornerRadius:10.0];
//Set the border color
[self.settingsView.layer setBorderColor:[[UIColor whiteColor] CGColor]];
//Set the image border`enter code here`
[self.settingsView.layer setBorderWidth:2.0];
0

精彩评论

暂无评论...
验证码 换一张
取 消