title: UIView Round Corners with Shadow
body: <p>I am trying to display a UIView with round corners and with a drop shadow. But the problem is that maskToBounds property only works for either of the case. </p>
  
  <p>If maskToBounds is YES then round corners show up and when NO then shadow shows up. Here is the implementation but it only displays round corners with no shadow: </p>
  
  <pre><code>[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_gradient.jpeg"]]];
  
  
      self.view.layer.masksToBounds = YES; 
      self.view.layer.opaque = NO; 
      self.view.layer.cornerRadius = 15.0f; 
  
  
      self.view.layer.shadowColor = [UIColor blackColor].CGColor;
      self.view.layer.shadowRadius = 5.0; 
      self.view.layer.shadowOffset = CGSizeMake(3.0, 3.0);
      self.view.layer.shadowOpacity = 0.9f;
  </code></pre>
  
  <p>ideas!</p>
  
  <p>NOTE: I have read and implemented the code in the following thread but it does not work: 
  <a href="https://stackoverflow.com/questions/4754392/uiview-with-rounded-corners-and-drop-shadow">UIView with rounded corners and drop shadow?</a></p>
  
  <p><strong>UPDATE 1:</strong> </p>
  
  <p>I tried to create two separate views. One will represent the radius and one will represent the shadow. The problem is that is creates the shadow on top of the radius view as shown in the screenshot below: </p>
  
  <p><img src="https://i.stack.imgur.com/1EiIh.png" alt="enter image description here"></p>
  
  <p>H</p>
  
  <pre><code>ere is the code: 
  
   self.view.layer.masksToBounds = YES; 
      self.view.layer.opaque = NO; 
      self.view.layer.cornerRadius = 15.0f; 
     // self.view.backgroundColor = [UIColor clearColor];
      self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_gradient.jpeg"]];
  //
      UIView *shadowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
      shadowView.layer.shadowColor = [UIColor blackColor].CGColor;
      shadowView.layer.shadowRadius = 2.0; 
      shadowView.backgroundColor = [UIColor clearColor];
      shadowView.layer.shadowOffset = CGSizeMake(3.0, 3.0);
      shadowView.layer.shadowOpacity = 0.9f;
      shadowView.layer.shadowPath = [UIBezierPath 
                                                                     bezierPathWithRect:CGRectMake(0, 0, 100, 100)].CGPath;
  
      [self.view addSubview:shadowView];
  </code></pre>
  
  <p>UPDATE 2: </p>
  
  <p>Inverted still does not work. No round corners are created. </p>
  
  <pre><code>UIView *roundCornerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
      roundCornerView.layer.masksToBounds = YES; 
      roundCornerView.layer.opaque = NO; 
      roundCornerView.layer.cornerRadius = 15.0f; 
  
      self.view.layer.shadowColor = [UIColor blackColor].CGColor;
      self.view.layer.shadowRadius = 2.0; 
      //self.view.backgroundColor = [UIColor clearColor];
      self.view.layer.shadowOffset = CGSizeMake(3.0, 3.0);
      self.view.layer.shadowOpacity = 0.9f;
      self.view.layer.shadowPath = [UIBezierPath 
                                                                     bezierPathWithRect:CGRectMake(0, 0, 100, 100)].CGPath;
  
      [self.view addSubview:roundCornerView];
  </code></pre>
  
  <p><strong>SOLUTION:</strong> </p>
  
  <pre><code> UIView *roundCornerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
      roundCornerView.layer.masksToBounds = YES; 
      roundCornerView.layer.opaque = NO; 
      roundCornerView.layer.cornerRadius = 15.0f; 
  
      roundCornerView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_gradient.jpeg"]];
  
      self.view.layer.shadowColor = [UIColor blackColor].CGColor;
      self.view.layer.shadowRadius = 2.0; 
      self.view.backgroundColor = [UIColor clearColor];
      self.view.layer.shadowOffset = CGSizeMake(3.0, 3.0);
      self.view.layer.shadowOpacity = 0.9f;
      //self.view.layer.shadowPath = [UIBezierPath 
        //                                                             bezierPathWithRect:CGRectMake(0, 0, 100, 100)].CGPath;
  
      [self.view addSubview:roundCornerView];
  </code></pre>