sold
sold

Reputation: 314

Add black shadow to UIView maskView

Can't seem to find an answer for this...

So I'm adding a mask to a UIView like so

    //create mask image for uiview
UIImageView *imv = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,  self.sentencesContainer.frame.size.width, self.sentencesContainer.frame.size.height)];
imv.image = new;
self.sentencesContainer.maskView = imv;

Then trying to add a shadow to the mask.

self.sentencesContainer.maskView.layer.masksToBounds = NO;
self.sentencesContainer.maskView.layer.cornerRadius = 10; 
self.sentencesContainer.maskView.layer.shadowOffset = CGSizeMake(distanceX, distanceY);
self.sentencesContainer.maskView.layer.shadowRadius = 2;
self.sentencesContainer.maskView.layer.shadowOpacity = opacity;
self.sentencesContainer.maskView.layer.shadowColor = [UIColor blackColor].CGColor;

But the shadow does not become black. It just keeps the same color as the view. I've tried adding the shadow to the view layer too but that does no get the shadow around the masked part. Any suggestions how to get it black?

Upvotes: 1

Views: 232

Answers (1)

Mani Palanivel
Mani Palanivel

Reputation: 73

Add the following line as well.

self.sentencesContainer.maskView.clipsToBounds = NO; self.sentencesContainer.maskView.layer.zposition = 9999;

So that it will bring your shadow effect to front over other view.

Upvotes: 1

Related Questions