ios - 如何使用圆角向 UIView 添加内部阴影
问题描述
UIView
我必须为圆角添加一个内部阴影。
我在 SO 上看到了几个答案,它们向 UIViews 添加了内部阴影,但它们不能按我的意愿工作,因为它们将阴影添加到整个矩形,而不是考虑圆角。
将此图像视为我想要实现的示例:
解决方案
这是一个把戏。您将阴影和边框赋予同一视图,阴影将落在视图内。请确保视图的背景颜色清晰。使用下面的代码作为参考。
yourView.layer.shadowColor = UIColor.gray.cgColor
yourView.layer.shadowOpacity = 0.3
yourView.layer.shadowOffset = CGSize.zero
yourView.layer.shadowRadius = 6
yourView.layer.masksToBounds = true
yourView.layer.borderWidth = 1.5
yourView.layer.borderColor = UIColor.white.cgColor
yourView.layer.cornerRadius = imageView.bounds.width / 2
推荐阅读
- r - 如何根据另一列的相等性对列的值求和并创建新的数据框
- libreoffice-calc - Excel 到 Libreoffice 的宏转换 - RefreshTable
- spring - 跨 Spring Boot Server 运行持久化的状态数据示例
- f# - 可以在完整的 Web 应用程序中使用 F#
- redux - 反应 redux createSlice 或 createReducer
- c# - 如何触发 ViewModel 中的方法?
- vb.net - 创建一个列表(位图)绘制一个列表(字符串)
- python - 无法在 VScode 上安装 pyaudio
- c - 尝试锁定 EOWNERDEAD 状态互斥锁
- google-apps-script - 我应该如何在 Google 表格中显示 ~1600 个迷你图?