似乎无法找到答案...
所以我正在为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 :(得分:1)
也添加以下行。
self.sentencesContainer.maskView.clipsToBounds = NO; self.sentencesContainer.maskView.layer.zposition = 9999;
这样它会将阴影效果置于其他视图的前方。