Dark mode implemented

This commit is contained in:
James Magahern
2020-07-29 18:17:22 -07:00
parent 32cdcf71f7
commit 220fc6f070
7 changed files with 163 additions and 3 deletions

View File

@@ -23,17 +23,20 @@ class URLBar: UIView
private let backgroundView = UIVisualEffectView(effect: UIBlurEffect(style: .systemThickMaterial))
private let progressIndicatorView = ProgressIndicatorView()
private let fadeMaskView = UIImageView(frame: .zero)
private let refreshImage = UIImage(systemName: "arrow.clockwise")
private let stopImage = UIImage(systemName: "xmark")
private let backgroundCornerRadius: CGFloat = 8
convenience init() {
self.init(frame: .zero)
backgroundColor = .clear
backgroundView.layer.masksToBounds = true
backgroundView.layer.cornerRadius = 8
backgroundView.layer.cornerRadius = backgroundCornerRadius
backgroundView.layer.borderWidth = 1
backgroundView.layer.borderColor = UIColor.systemFill.cgColor
backgroundView.isUserInteractionEnabled = false
@@ -85,12 +88,47 @@ class URLBar: UIView
return CGSize(width: 1000.0, height: preferredHeight)
}
private func fadeBackgroundImageForSize(_ size: CGSize) -> UIImage? {
var image: UIImage? = nil
UIGraphicsBeginImageContext(CGSize(width: size.width, height: 1.0))
if let context = UIGraphicsGetCurrentContext() {
let gradientColorsArray = [
UIColor(white: 1.0, alpha: 1.0).cgColor,
UIColor(white: 1.0, alpha: 1.0).cgColor,
UIColor(white: 1.0, alpha: 0.08).cgColor,
UIColor(white: 1.0, alpha: 0.08).cgColor
]
let locations: [CGFloat] = [
0.0, 0.80, 0.90, 1.0
]
if let gradient = CGGradient(colorsSpace: nil, colors: gradientColorsArray as CFArray, locations: locations) {
context.drawLinearGradient(gradient, start: .zero, end: CGPoint(x: size.width, y: 0.0), options: CGGradientDrawingOptions())
}
image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
}
return image
}
override func layoutSubviews() {
super.layoutSubviews()
backgroundView.frame = bounds
progressIndicatorView.frame = backgroundView.contentView.bounds
textField.frame = bounds.insetBy(dx: 6.0, dy: 0)
fadeMaskView.frame = textField.bounds
fadeMaskView.image = fadeBackgroundImageForSize(fadeMaskView.frame.size)
if !textField.isFirstResponder {
textField.mask = fadeMaskView
} else {
textField.mask = nil
}
let refreshButtonSize = CGSize(width: textField.frame.height, height: textField.frame.height)
refreshButton.frame = CGRect(origin: CGPoint(x: bounds.width - refreshButtonSize.width, y: 0), size: refreshButtonSize)
}