2017-06-22 98 views
1

似乎无法找到这个答案...黑色阴影添加到UIView的maskView

所以我加一个遮蔽一个UIView像这样

//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; 

然后尝试添加面具的影子。

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; 

但是阴影不会变成黑色。它只是保持与视图相同的颜色。我已经尝试向视图图层添加阴影,但是不会在蒙版部分获得阴影。任何建议如何让它变黑?

+0

你想为UIView或UIImageview设置阴影吗? –

+0

我想将阴影设置为UIView.maskView。 self.sentencesContainer是一个UIView。 –

回答

1

也添加以下行。

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

这样它会使你的阴影效果超过其他视图。

+0

谢谢,但这并不能解决我错误颜色的问题... –