// // URLBar.swift // SBrowser // // Created by James Magahern on 7/23/20. // import UIKit class URLBar: UIView { let textField = UITextField(frame: .zero) let refreshButton = UIButton(frame: .zero) private let backgroundView = UIVisualEffectView(effect: UIBlurEffect(style: .systemThickMaterial)) convenience init() { self.init(frame: .zero) backgroundColor = .clear backgroundView.layer.masksToBounds = true backgroundView.layer.cornerRadius = 8 backgroundView.layer.borderWidth = 1 backgroundView.layer.borderColor = UIColor.systemFill.cgColor backgroundView.isUserInteractionEnabled = false addSubview(backgroundView) textField.backgroundColor = .clear textField.textContentType = .URL textField.keyboardType = .webSearch textField.autocorrectionType = .no textField.autocapitalizationType = .none textField.font = .preferredFont(forTextStyle: .body) textField.clearingBehavior = .clearOnInsertionAndShowSelectionTint addSubview(textField) refreshButton.tintColor = .secondaryLabel refreshButton.setImage(UIImage(systemName: "arrow.clockwise"), for: .normal) addSubview(refreshButton) } override var intrinsicContentSize: CGSize { let preferredHeight = CGFloat(34) return CGSize(width: 1000.0, height: preferredHeight) } override func layoutSubviews() { super.layoutSubviews() backgroundView.frame = bounds textField.frame = bounds.insetBy(dx: 6.0, dy: 0) 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) } }