Show app name in titlebar
This commit is contained in:
@@ -154,7 +154,7 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
|
||||
}
|
||||
|
||||
private func updateTitleAndURL(forWebView webView: WKWebView) {
|
||||
browserView.titlebarView.titleLabelView.text = webView.title
|
||||
browserView.titlebarView.setTitle(webView.title ?? "")
|
||||
|
||||
if let urlString = webView.url?.absoluteString {
|
||||
toolbarController.urlBar.textField.text = urlString
|
||||
|
||||
@@ -9,7 +9,7 @@ import UIKit
|
||||
|
||||
class TitlebarView: UIView
|
||||
{
|
||||
public let titleLabelView = UILabel(frame: .zero)
|
||||
private let titleLabelView = UILabel(frame: .zero)
|
||||
private let backgroundImageView = UIImageView(frame: .zero)
|
||||
|
||||
convenience init() {
|
||||
@@ -25,6 +25,29 @@ class TitlebarView: UIView
|
||||
|
||||
backgroundImageView.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)
|
||||
}
|
||||
}
|
||||
|
||||
private func backgroundImageForSize(_ size: CGSize) -> UIImage? {
|
||||
var image: UIImage? = nil
|
||||
|
||||
Reference in New Issue
Block a user