Last active
February 9, 2019 15:27
-
-
Save amichnia/8f84d31746e8ba9977553f73847ee044 to your computer and use it in GitHub Desktop.
Debug UIWindow with version label above EVERYTHING
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class Debug { | |
static var window: UIWindow? | |
static func setupWindowIfNeeded() { | |
guard Debug.window == nil else { return } | |
guard Environment.current != .release else { return } | |
let window = UIWindow(frame: UIScreen.main.bounds) | |
window.backgroundColor = .clear | |
#if swift(>=4.2) | |
window.windowLevel = UIWindow.Level.alert + 1 | |
#else | |
window.windowLevel = UIWindowLevelAlert + 1 | |
#endif | |
window.isUserInteractionEnabled = false | |
window.clipsToBounds = false | |
let label = UILabel() | |
label.translatesAutoresizingMaskIntoConstraints = false | |
label.text = Environment.current.versionInfo | |
label.font = UIFont.systemFont(ofSize: 8) | |
label.textColor = UIColor.lightGray | |
label.shadowColor = UIColor.darkGray | |
label.textAlignment = .right | |
let dummy = UIViewController() | |
dummy.view.backgroundColor = UIColor.clear | |
window.rootViewController = dummy | |
dummy.view.addSubview(label) | |
label.rightAnchor.constraint(equalTo: dummy.view.rightAnchor).isActive = true | |
label.leftAnchor.constraint(equalTo: dummy.view.leftAnchor).isActive = true | |
label.bottomAnchor.constraint(equalTo: dummy.view.bottomAnchor, constant: -1).isActive = true | |
label.heightAnchor.constraint(equalToConstant: 12).isActive = true | |
#if swift(>=4.2) | |
dummy.view.bringSubviewToFront(label) | |
#else | |
dummy.view.bringSubview(toFront: label) | |
#endif | |
window.isHidden = false | |
Debug.window = window | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment