【问题标题】:Add black shadow to UIView maskView给 UIView maskView 添加黑色阴影
【发布时间】:2017-06-22 08:41:26
【问题描述】:

似乎找不到答案...

所以我要像这样向 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;

但是阴影不会变黑。它只是保持与视图相同的颜色。我也尝试将阴影添加到视图层,但这并没有在被遮罩的部分周围产生阴影。有什么建议可以让它变黑吗?

【问题讨论】:

  • 你想给 UIView 或 UIImageview 设置阴影?
  • 我想给 UIView.maskView 设置阴影。 self.sentencesContainer 是一个 UIView。

标签: ios objective-c uiview shadow


【解决方案1】:

也添加以下行。

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

这样它会将你的阴影效果带到其他视图的前面。

【讨论】:

    猜你喜欢
    • 2015-10-23
    • 2018-07-19
    • 1970-01-01
    • 2014-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多