问题描述:

There are a lot of questions about how to draw a drop shadow for a view. But how can I have my view cast a shadow that is received only by one other view?

网友答案:

If view A is the view with the shadow and view B is the parent of A, you can set masksToBounds which is a property of B's layer to YES.

Contents of B and its subviews will not be shown outside of B. They will be clipped.

More detail here: what UIView layer.masksToBounds is doing if set to YES

However, if you want the shadow drops on more complex scene, you might need to be a little more specific.

网友答案:
  • Make an app with a white background.
  • Make your view plus shadow.
  • Take a screen shot.
  • Use the screen shot in your original app.

Of course you could also make the picture on the fly in code, but that is a bit more challenging. In any case, it would be code you do not need in your final app.

相关阅读:
Top