Show app name in titlebar

This commit is contained in:
James Magahern
2020-07-31 17:44:38 -07:00
parent c723b3de88
commit 2a64636d61
3 changed files with 114 additions and 2 deletions

View File

@@ -154,7 +154,7 @@ class BrowserViewController: UIViewController, WKNavigationDelegate,
} }
private func updateTitleAndURL(forWebView webView: WKWebView) { private func updateTitleAndURL(forWebView webView: WKWebView) {
browserView.titlebarView.titleLabelView.text = webView.title browserView.titlebarView.setTitle(webView.title ?? "")
if let urlString = webView.url?.absoluteString { if let urlString = webView.url?.absoluteString {
toolbarController.urlBar.textField.text = urlString toolbarController.urlBar.textField.text = urlString

View File

@@ -9,7 +9,7 @@ import UIKit
class TitlebarView: UIView class TitlebarView: UIView
{ {
public let titleLabelView = UILabel(frame: .zero) private let titleLabelView = UILabel(frame: .zero)
private let backgroundImageView = UIImageView(frame: .zero) private let backgroundImageView = UIImageView(frame: .zero)
convenience init() { convenience init() {
@@ -26,6 +26,29 @@ class TitlebarView: UIView
backgroundImageView.alpha = 0.98 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? { private func backgroundImageForSize(_ size: CGSize) -> UIImage? {
var image: UIImage? = nil var image: UIImage? = nil

View File

@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1200"
version = "2.0">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1ADFF45B24C7DE53006DC7AE"
BuildableName = "App.app"
BlueprintName = "App"
ReferencedContainer = "container:SBrowser.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES"
internalIOSLaunchStyle = "2">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1ADFF45B24C7DE53006DC7AE"
BuildableName = "App.app"
BlueprintName = "App"
ReferencedContainer = "container:SBrowser.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
<AdditionalOption
key = "MallocScribble"
value = ""
isEnabled = "YES">
</AdditionalOption>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "1ADFF45B24C7DE53006DC7AE"
BuildableName = "App.app"
BlueprintName = "App"
ReferencedContainer = "container:SBrowser.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
<InstallAction
buildConfiguration = "Release">
</InstallAction>
</Scheme>