1
0
mirror of https://github.com/mastodon/mastodon-ios.git synced 2024-12-15 18:29:36 +01:00
mastodon-app-ufficiale-ipho.../MastodonSDK/Sources/MastodonExtension/CALayer.swift

51 lines
1.4 KiB
Swift
Raw Normal View History

2021-03-02 05:49:04 +01:00
//
// CALayer.swift
// Mastodon
//
// Created by Cirno MainasuK on 2021-2-26.
//
import UIKit
extension CALayer {
2022-01-05 08:11:35 +01:00
public func setupShadow(
2021-03-02 05:49:04 +01:00
color: UIColor = .black,
alpha: Float = 0.5,
x: CGFloat = 0,
y: CGFloat = 2,
blur: CGFloat = 4,
spread: CGFloat = 0,
roundedRect: CGRect? = nil,
byRoundingCorners corners: UIRectCorner? = nil,
cornerRadii: CGSize? = nil
) {
// assert(roundedRect != .zero)
shadowColor = color.cgColor
shadowOpacity = alpha
shadowOffset = CGSize(width: x, height: y)
shadowRadius = blur / 2
rasterizationScale = UIScreen.main.scale
shouldRasterize = true
masksToBounds = false
guard let roundedRect = roundedRect,
let corners = corners,
let cornerRadii = cornerRadii else {
return
}
if spread == 0 {
shadowPath = UIBezierPath(roundedRect: roundedRect, byRoundingCorners: corners, cornerRadii: cornerRadii).cgPath
} else {
let rect = roundedRect.insetBy(dx: -spread, dy: -spread)
shadowPath = UIBezierPath(roundedRect: rect, byRoundingCorners: corners, cornerRadii: cornerRadii).cgPath
}
}
2022-01-05 08:11:35 +01:00
public func removeShadow() {
2021-03-02 05:49:04 +01:00
shadowRadius = 0
}
2022-01-05 08:11:35 +01:00
2021-03-02 05:49:04 +01:00
}