【问题标题】:View Shadow in iOS在 iOS 中查看阴影
【发布时间】:2014-02-28 08:19:58
【问题描述】:

我已经实现了一个看起来像这样的视图 -

但我希望视图的底部看起来像这样 -

添加阴影无济于事,因为只要我这样做maskToBounds = YES,我就会得到第一张照片中的内容。这是我到目前为止的代码

[self.contentView.layer setCornerRadius:3.0f];
UIColor* color = CardBorderColor; // this is a macro that defines the color
[self.contentView.layer setBorderColor:color.CGColor];
[self.contentView.layer setBorderWidth:1.0f];
[self.contentView.layer setShadowColor:color.CGColor];
[self.contentView.layer setShadowOpacity:1.0];
[self.contentView.layer setShadowRadius:3.0];
[self.contentView.layer setShadowOffset:CGSizeMake(1.0, 1.0)];
self.contentView.layer.masksToBounds = YES;

【问题讨论】:

  • 哇,我不知道为什么有人投了反对票。完全合法的问题。 (我投票 +1 将其设为 0。)您绝对需要 maskToBounds = YES 吗?如果您需要将它用于另一个元素,请尝试将需要 maskToBounds 的视图放在另一个视图中,并将阴影添加到底部视图。

标签: ios iphone objective-c uiview core-graphics


【解决方案1】:

很遗憾,是的,使用masksToBounds 会掩盖你的影子。如果您需要为该视图中的另一个元素设置 maskToBounds = YES,则将需要 maskToBounds 的视图放在另一个 UIView 之上,并将阴影添加到该底部视图。

【讨论】:

  • 这就是我最终要做的——添加了阴影颜色的父视图,并使当前视图小 3 像素并添加到该父视图。它看起来像我想要的那样。谢谢!
【解决方案2】:
猜你喜欢
  • 2017-09-21
  • 1970-01-01
  • 2013-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多