Last active
February 8, 2024 23:23
-
-
Save chriszielinski/359ca5ef45d2d652dfb8857aa127136b to your computer and use it in GitHub Desktop.
NSViewController extension for fetching a window title's NSTextField
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
extension NSViewController { | |
var titlebarTextField: NSTextField? { | |
// NSTitlebarContainerView | |
guard let titlebarContainerView = view.superview?.subviews | |
.first(where: { $0.className.hasSuffix("ContainerView") }) | |
else { return nil } | |
// NSTitlebarView | |
guard let titlebarView = titlebarContainerView.subviews | |
.first(where: { $0.className.hasSuffix("TitlebarView") }) as? NSVisualEffectView | |
else { return nil } | |
// NSTextField | |
return titlebarView.subviews | |
.first(where: { $0 is NSTextField }) as? NSTextField | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment