Rename to rossler\\attix

This commit is contained in:
James Magahern
2020-07-31 17:35:03 -07:00
parent 030c1db45c
commit c723b3de88
30 changed files with 25 additions and 207 deletions

View File

@@ -0,0 +1,72 @@
//
// ScriptPolicyControl.swift
// SBrowser
//
// Created by James Magahern on 7/24/20.
//
import UIKit
class ScriptPolicyControl: UIControl
{
enum PolicyStatus {
case allowed
case blocked
}
var policyStatus: PolicyStatus = .blocked {
didSet { setNeedsLayout() }
}
private class PolicyButton: UIButton {
override func imageRect(forContentRect contentRect: CGRect) -> CGRect {
contentRect.insetBy(dx: 8.0, dy: 8.0)
}
}
private let allowButton = PolicyButton(frame: .zero)
private let denyButton = PolicyButton(frame: .zero)
convenience init() {
self.init(frame: .zero)
allowButton.addAction(UIAction(handler: { [unowned self] _ in
self.policyStatus = .allowed
self.sendActions(for: .valueChanged)
}), for: .touchUpInside)
allowButton.imageView?.contentMode = .scaleAspectFit
addSubview(allowButton)
denyButton.addAction(UIAction(handler: { [unowned self] _ in
self.policyStatus = .blocked
self.sendActions(for: .valueChanged)
}), for: .touchUpInside)
denyButton.imageView?.contentMode = .scaleAspectFit
addSubview(denyButton)
}
override var intrinsicContentSize: CGSize {
CGSize(width: 100.0, height: UIView.noIntrinsicMetric)
}
override func layoutSubviews() {
super.layoutSubviews()
allowButton.frame = CGRect(origin: .zero, size: CGSize(width: bounds.width / 2, height: bounds.height))
denyButton.frame = CGRect(origin: CGPoint(x: allowButton.frame.maxX, y: 0), size: allowButton.frame.size)
if policyStatus == .allowed {
allowButton.tintColor = .blue
allowButton.setImage(UIImage(systemName: "play.circle.fill"), for: .normal)
denyButton.tintColor = .darkGray
denyButton.setImage(UIImage(systemName: "stop.circle"), for: .normal)
} else {
allowButton.tintColor = .darkGray
allowButton.setImage(UIImage(systemName: "play.circle"), for: .normal)
denyButton.tintColor = .red
denyButton.setImage(UIImage(systemName: "stop.circle.fill"), for: .normal)
}
}
}