Kurdtvs-Live-Kurdish-TV-Kur.../MastodonSDK/Sources/MastodonUI/View/Container/ShadowBackgroundContainer.s...

61 lines
1.3 KiB
Swift
Raw Normal View History

2022-01-05 08:11:35 +01:00
//
// ShadowBackgroundContainer.swift
//
//
// Created by MainasuK on 2022-1-5.
//
import UIKit
import MastodonExtension
public final class ShadowBackgroundContainer: UIView {
2022-01-07 11:49:37 +01:00
public var shadowAlpha: CGFloat = 0.25 {
didSet { setNeedsLayout() }
}
public var shadowColor: UIColor = .black {
didSet { setNeedsLayout() }
}
public var cornerRadius: CGFloat = 10 {
didSet { setNeedsLayout() }
}
2022-01-05 08:11:35 +01:00
public let shadowLayer = CALayer()
override init(frame: CGRect) {
super.init(frame: frame)
_init()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
_init()
}
}
extension ShadowBackgroundContainer {
private func _init() {
layer.insertSublayer(shadowLayer, at: 0)
}
public override func layoutSubviews() {
super.layoutSubviews()
shadowLayer.frame = bounds
shadowLayer.setupShadow(
2022-01-07 11:49:37 +01:00
color: shadowColor,
alpha: Float(shadowAlpha),
2022-01-05 08:11:35 +01:00
x: 0,
y: 1,
blur: 2,
spread: 0,
roundedRect: bounds,
byRoundingCorners: .allCorners,
2022-01-07 11:49:37 +01:00
cornerRadii: CGSize(width: cornerRadius, height: cornerRadius)
2022-01-05 08:11:35 +01:00
)
}
}