问题
forgive me if this is an obvious question i am relatively new.
I have a modal view which i set up with a custom size and rounded corners:
- (void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
self.view.superview.bounds = CGRectMake(0, 0, 600, 450);
self.view.layer.cornerRadius = 60.0;
}
However i find that when i round the view corners, i get this greyish colour appear on the edges of it (as if theres something else behind it) : (see picture).
How do i remove these greyish edges so it shows the background content like normal? I've tried adding
self.view.layer.masksToBounds = YES;
however this still gives the same effect as above.
Thanks,
回答1:
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.view.superview.bounds = CGRectMake(0, 0, 600, 450);
self.view.superview.layer.cornerRadius = 60.0;
self.view.superview.layer.masksToBounds = YES;
}
I think you should set corner radius of the superView.
回答2:
use like this
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.view.superview.bounds = CGRectMake(0, 0, 600, 450);
self.view.layer.cornerRadius = 60.0;
self.view.layer.masksToBounds = YES; //add this line
}
回答3:
Use this, it will remove the shadow
self.view.layer.masksToBounds = YES;
回答4:
It turns out you need to round the superview and mask the superview;
[self.view superview].layer.cornerRadius = 30.0f;
[self.view superview].layer.masksToBounds = YES;
So in the end its looked like this :)
- (void)viewWillLayoutSubviews{
//setup custom size modal view
[super viewWillLayoutSubviews];
self.view.superview.bounds = CGRectMake(0, 0, 600, 450);
[self.view superview].layer.cornerRadius = 30.0f;
[self.view superview].layer.masksToBounds = YES;
}
Thanks for your help Shan
来源:https://stackoverflow.com/questions/20609717/rounding-corners-of-uimodalpresentationformsheet