Rounding corners of UIModalPresentationFormSheet

3.3k views Asked by At

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

There are 4 answers

2
johnMa On BEST ANSWER
- (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.

0
Fudgey On

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

1
Shankar BS On

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 

 }


2
chandru On

Use this, it will remove the shadow

self.view.layer.masksToBounds = YES;