Rounding corners of UIModalPresentationFormSheet

2020-05-29 05:54发布

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).

enter image description here

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,

4条回答
在下西门庆
2楼-- · 2020-05-29 06:27
- (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.

查看更多
beautiful°
3楼-- · 2020-05-29 06:44

Use this, it will remove the shadow

self.view.layer.masksToBounds = YES;
查看更多
对你真心纯属浪费
4楼-- · 2020-05-29 06:44

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

查看更多
Bombasti
5楼-- · 2020-05-29 06:46

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 

 }


查看更多
登录 后发表回答