Files
Attractor/App/Titlebar and URL Bar/TitlebarView.swift
2020-08-14 15:55:08 -07:00

62 lines
2.2 KiB
Swift

//
// TitlebarView.swift
// SBrowser
//
// Created by James Magahern on 7/29/20.
//
import UIKit
class TitlebarView: UIView
{
private let titleLabelView = UILabel(frame: .zero)
private let backgroundView = GradientView(direction: .horizontal, colors: [
UIColor(red: 0.101, green: 0.176, blue: 0.415, alpha: 1.0),
UIColor(red: 0.153, green: 0.000, blue: 0.153, alpha: 1.0)
])
convenience init() {
self.init(frame: .zero)
addSubview(backgroundView)
addSubview(titleLabelView)
titleLabelView.textColor = .white
titleLabelView.layer.shadowColor = UIColor.black.cgColor
titleLabelView.layer.shadowRadius = 0.0
titleLabelView.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
titleLabelView.font = UIFont.boldSystemFont(ofSize: 12.0)
backgroundView.alpha = 0.98
}
func setTitle(_ title: String) {
let titleAttributes: [NSAttributedString.Key : Any] = [
.font : UIFont.boldSystemFont(ofSize: 12.0),
.foregroundColor : UIColor.white
]
let appName = Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as! String
let appNameAttributes: [NSAttributedString.Key : Any] = [
.font : UIFont.systemFont(ofSize: 12.0),
.foregroundColor : UIColor(white: 1.0, alpha: 0.75)
]
if title.count > 0 {
let attributedString = NSMutableAttributedString(string: title, attributes: titleAttributes)
let appAttributedString = NSAttributedString(string: " :: \(appName)", attributes: appNameAttributes)
attributedString.append(appAttributedString)
titleLabelView.attributedText = attributedString
} else {
titleLabelView.attributedText = NSAttributedString(string: appName, attributes: titleAttributes)
}
}
override func layoutSubviews() {
super.layoutSubviews()
backgroundView.frame = bounds
titleLabelView.frame = bounds.avoiding(verticalInsets: safeAreaInsets).insetBy(dx: 8.0 + layoutMargins.left, dy: 0.0)
}
}