2021-02-04 08:09:58 +01:00
|
|
|
//
|
|
|
|
// UIView.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/2/4.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
|
2021-07-02 07:21:05 +02:00
|
|
|
// MARK: - Convenience view creation method
|
2021-02-04 08:09:58 +01:00
|
|
|
extension UIView {
|
2021-07-02 07:21:05 +02:00
|
|
|
|
|
|
|
static let separatorColor: UIColor = {
|
|
|
|
UIColor(dynamicProvider: { collection in
|
|
|
|
switch collection.userInterfaceStyle {
|
|
|
|
case .dark:
|
2021-07-05 10:07:17 +02:00
|
|
|
return ThemeService.shared.currentTheme.value.separator
|
2021-07-02 07:21:05 +02:00
|
|
|
default:
|
|
|
|
return .separator
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}()
|
2021-02-04 08:09:58 +01:00
|
|
|
|
|
|
|
static var separatorLine: UIView {
|
|
|
|
let line = UIView()
|
2021-07-02 07:21:05 +02:00
|
|
|
line.backgroundColor = UIView.separatorColor
|
2021-02-04 08:09:58 +01:00
|
|
|
return line
|
|
|
|
}
|
|
|
|
|
|
|
|
static func separatorLineHeight(of view: UIView) -> CGFloat {
|
|
|
|
return 1.0 / view.traitCollection.displayScale
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-02-20 13:23:29 +01:00
|
|
|
|
2021-06-23 14:47:49 +02:00
|
|
|
// MARK: - Convenience view appearance modification method
|
2021-02-20 13:23:29 +01:00
|
|
|
extension UIView {
|
|
|
|
@discardableResult
|
|
|
|
func applyCornerRadius(radius: CGFloat) -> Self {
|
|
|
|
layer.masksToBounds = true
|
|
|
|
layer.cornerRadius = radius
|
|
|
|
layer.cornerCurve = .continuous
|
|
|
|
return self
|
|
|
|
}
|
2021-02-23 15:14:10 +01:00
|
|
|
|
|
|
|
@discardableResult
|
|
|
|
func applyShadow(
|
|
|
|
color: UIColor,
|
|
|
|
alpha: Float,
|
|
|
|
x: CGFloat,
|
|
|
|
y: CGFloat,
|
|
|
|
blur: CGFloat,
|
|
|
|
spread: CGFloat = 0) -> Self
|
|
|
|
{
|
|
|
|
layer.masksToBounds = false
|
|
|
|
layer.shadowColor = color.cgColor
|
|
|
|
layer.shadowOpacity = alpha
|
|
|
|
layer.shadowOffset = CGSize(width: x, height: y)
|
|
|
|
layer.shadowRadius = blur / 2.0
|
|
|
|
if spread == 0 {
|
|
|
|
layer.shadowPath = nil
|
|
|
|
} else {
|
|
|
|
let dx = -spread
|
|
|
|
let rect = bounds.insetBy(dx: dx, dy: dx)
|
|
|
|
layer.shadowPath = UIBezierPath(rect: rect).cgPath
|
|
|
|
}
|
|
|
|
return self
|
|
|
|
}
|
2021-02-20 13:23:29 +01:00
|
|
|
}
|
2021-08-04 10:24:19 +02:00
|
|
|
|