UIView 阴影未在 iphone 5 秒内显示
UIView shadow not showing in iphone 5s
我有一个 UIView 并想给它添加阴影。所以我得到下面给出的代码,它在所有 iphone 模拟器和设备中运行良好,但在 iphone 5s 和模拟器中也没有显示阴影。
class ShadowView: UIView {
override var bounds: CGRect {
didSet {
setupShadow()
}
}
private func setupShadow() {
self.layer.cornerRadius = 2
self.layer.shadowOffset = CGSize(width: 1, height: 1)
self.layer.shadowRadius = 4
self.layer.shadowOpacity = 0.5
self.layer.shadowPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: 2, height: 2)).cgPath
self.layer.shouldRasterize = true
self.layer.rasterizationScale = UIScreen.main.scale
}
}
希望对您有所帮助!!
import UIKit
class ShadowView: UIView {
override func awakeFromNib() {
super.awakeFromNib()
setupView()
}
func setupView() {
self.layer.cornerRadius = 5.0
self.layer.shadowOpacity = 1.0
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowOffset = CGSize(width: -1, height: 1)
self.layer.masksToBounds = false
self.layer.shadowRadius = 3.0
self.layer.shouldRasterize = true
}
}
我有一个 UIView 并想给它添加阴影。所以我得到下面给出的代码,它在所有 iphone 模拟器和设备中运行良好,但在 iphone 5s 和模拟器中也没有显示阴影。
class ShadowView: UIView {
override var bounds: CGRect {
didSet {
setupShadow()
}
}
private func setupShadow() {
self.layer.cornerRadius = 2
self.layer.shadowOffset = CGSize(width: 1, height: 1)
self.layer.shadowRadius = 4
self.layer.shadowOpacity = 0.5
self.layer.shadowPath = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: .allCorners, cornerRadii: CGSize(width: 2, height: 2)).cgPath
self.layer.shouldRasterize = true
self.layer.rasterizationScale = UIScreen.main.scale
}
}
希望对您有所帮助!!
import UIKit
class ShadowView: UIView {
override func awakeFromNib() {
super.awakeFromNib()
setupView()
}
func setupView() {
self.layer.cornerRadius = 5.0
self.layer.shadowOpacity = 1.0
self.layer.shadowColor = UIColor.black.cgColor
self.layer.shadowOffset = CGSize(width: -1, height: 1)
self.layer.masksToBounds = false
self.layer.shadowRadius = 3.0
self.layer.shouldRasterize = true
}
}