【问题标题】:Shadow at top side of UIView only仅 UIView 顶部的阴影
【发布时间】:2020-06-30 14:15:47
【问题描述】:

如何从视图底部移除阴影? 这是我的 shadowView 的代码:

class ShadowViewWhite: UIView {

init() {
    super.init(frame: .zero)
    backgroundColor = .white
    layer.shadowColor = UIColor(red: 0.5, green: 0.5, blue: 0.65, alpha: 0.9).cgColor
    layer.shadowOpacity = 1
    layer.shadowRadius = 40
    layer.shadowOffset = CGSize(width: 0, height: -12)
}

required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

}

目前看起来就是这样。我需要阴影仅位于视图的顶部。

【问题讨论】:

  • 你能展示你想要的图片吗?
  • @MojtabaHosseini 我不想在我的白色视图下方有任何阴影效果,所以白色视图下的空间也应该是白色的
  • 添加未连接到屏幕边缘的视图图像

标签: swift uikit shadow


【解决方案1】:

更改shadowRadius 属性。例如:

layer.shadowRadius = 24

【讨论】:

    【解决方案2】:

    使用较低的阴影半径值会有所帮助。您可以尝试使用 shadowRadius = 20。

    【讨论】:

      【解决方案3】:

      减少shadowRadiusshadowOffset 的组合应该会对您有所帮助。我在下面附上了我的代码,应该会对你有所帮助。

      class ShadowViewWhite: UIView {
          
          override init(frame:CGRect) {
              super.init(frame: frame)
              backgroundColor = .white
              layer.shadowColor = UIColor(red: 0.5, green: 0.5, blue: 0.65, alpha: 0.9).cgColor
              layer.shadowOpacity = 1
              layer.shadowRadius = 20
              layer.shadowOffset = CGSize(width: 0, height: -40)
          }
          
          required init?(coder: NSCoder) {
              fatalError("init(coder:) has not been implemented")
          }
          
      }
      

      此代码将生成以下图像:

      【讨论】:

        猜你喜欢
        • 2014-07-30
        • 2016-10-06
        • 1970-01-01
        • 2017-08-23
        • 1970-01-01
        • 2011-07-19
        • 2011-10-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多