Posts

Post marked as solved
3 Replies
1.9k Views
(macOS, Swift, storyboards)How can I have two windows open from the beginning? (without clicking any button)What I have tried:1- CREATE A NEW WINDOW- Main.storyboard I have a Window Controller from the library- I have created a New document Cocoa Class SecondViewController- Main.storyboard > I select View Controller. In Identity Inspector I select Class SecondViewController2- MAKE IT LAUNCH FROM THE BEGINNING- AppDelegate.swift inside applicationDidFinishLaunching: let storyboard = NSStoryboard(name: "Main", bundle: nil) let windowController = storyboard.instantiateController(withIdentifier: "MySecondController") as! NSWindowController windowController.showWindow(self)- I think my problem is how to identify MySecondController in Main.storyboardI tried to select Window inside Window Controller. Then go to Identity Inspector and Identifier. But when I run, it does not appear. How should I identify that second window, where exactly should I put MySecondController name? Or perhaps I have not created well the second window?
Posted Last updated
.
Post marked as solved
5 Replies
2.8k Views
(Swift, macOS, storyboard)I just try to display a web site inside the app. But I see nothing. It fails silentlyimport Cocoa import WebKit class ViewController: NSViewController { @IBOutlet weak var webView: WKWebView! override func viewDidLoad() { super.viewDidLoad() let url = URL(string: "https://www.apple.com") let request = URLRequest(url:url!) webView.load(request) } }There is a similar question here:https://forums.developer.apple.com/thread/92265It talks about the sandbox but I do not understand what I have to do. What I have to select and why?Thank you
Posted Last updated
.
Post marked as solved
3 Replies
612 Views
How can I put a simple label in a window with a vibrant background (similar to a semi-transparent window)I can make the window vibrant with that code:override func viewWillAppear() { super.viewWillAppear() let visualEffect = NSVisualEffectView() visualEffect.blendingMode = .behindWindow visualEffect.state = .active visualEffect.material = .light view.window?.contentView = visualEffect }But If I put a simple label with any text in the storyboard, the label is not visible. If I remove the code of the vibrant background the label appear again. Perhaps I should put the label in another layer? if so, how?
Posted Last updated
.
Post marked as solved
3 Replies
594 Views
I know how to close the current window. For instance, I can put that in their ViewController.swift: @IBAction func closeSelf(_ sender: NSButton) { self.view.window?.close() }But how can I close another window with a button that is in the ViewController.swift?
Posted Last updated
.
Post marked as solved
3 Replies
1.4k Views
(Swift 5, macOS, Xcode 11, Storyboards)I try to connect a menu button. I have googled it intensely and I am confused as there is little updated information. I am new and I am confused.What I have tried is to control drag from the menu button to the AppDelegate.swift and I have created an action. It works well if I print something. But I do not understand how can I make do something to an NSView or a label. For instance, in this example, I put a blue NSView in the storyboard and I try to fadeOut when I click button1 on the Menu. (In iOS I would put an outlet in the viewController.swift. But in macOS I suppose, it should be in the AppDelegate.swift? If I try to control drag from the NSView to the AppDelegate, it is not possible)I put that in the AppDelegate.swift:@IBActionfunc button1(_ sender: NSMenuItem) { print ("I click to button1 in the menu") // When I add that, I have an error: use of unresolved identifier 'nsView1'. // I do not know how to connect nsView1 with the button, if the button is in the AppDelegate.swift) NSAnimationContext.runAnimationGroup({ (context) in context.duration = 2.0 nsView1.animator().alphaValue = 0 } }I put that in the ViewController.swift:overridefunc viewDidLoad() { super.viewDidLoad() nsView1.wantsLayer = true nsView1.layer!.backgroundColor = NSColor.blue.cgColor }Where I should I put that and how to make the button recognize the nsView1 ?:@IBOutletweakvar nsView1: NSView!
Posted Last updated
.
Post marked as solved
3 Replies
579 Views
(Swift, macOS)I have a label inside an NSView and a window that are transparents. I try to make the Window transparent, the NSView semi-transparent but keep the Label non-transparent.This makes the NSView1 and the Label1 semi-transparent: @IBOutlet weak var NSView1: NSView! @IBOutlet weak var Label1: NSTextField! @IBAction func button1(_ sender: NSButton) { // window transparent: view.window?.isOpaque = false view.window?.backgroundColor = NSColor.clear // NSView 50% transparent NSView1.wantsLayer = true NSView1.layer?.backgroundColor = NSColor.white.cgColor NSView1.alphaValue = 0.5 // I tried a label non transparent, but I still see the label semi-transparent : // Label1.backgroundColor = NSColor.black.withAlphaComponent(1) // Label1.backgroundColor = NSColor.black }
Posted Last updated
.
Post not yet marked as solved
9 Replies
3.3k Views
I want a window to not appear at launch to be able to control later how and where. In storyboard I select Window / Attributes and deselect "Visible At Launch" but it still appears. I even tried a new project with no code and just one window and it happens the same. Am I missing anything? Why is it not working? How to hide the window at the beginning?
Posted Last updated
.
Post not yet marked as solved
15 Replies
6.3k Views
(macOS and Swift)I try to make a window with rounded corners but every solution I could find does not work when I remove the title bar (Attributes > Title Bar)Also, the window is semi-transparent: view.window?.isOpaque = false view.window?.backgroundColor = NSColor.clear view.window?.backgroundColor = NSColor(white: 1, alpha: 0.8)(It would be ok if it has the regular corners of any window. I do not need a lot of control over the corner radius if that makes things more complicated)
Posted Last updated
.
Post marked as solved
2 Replies
471 Views
Can Swift hide and show desktop disks and desktop files?Desktop disks can be controlled in Finder Preferences. Desktop files and folders can hided and showed with the terminal. I also can control both with AppleScript. I could not find any way to hide and show them with Swift. Is this possible?
Posted Last updated
.
Post marked as solved
5 Replies
2.4k Views
How to auto hide menu bar of the finder with Swift and MacOS?I can see the Apple documentation https://developer.apple.com/documentation/appkit/nsapplication/presentationoptions/1428541-autohidemenubarBut I do not understand how to apply that. I would appreciate any orientation.(By the way I know how to hide and show but what I am looling for is auto hide and only show when the user approach the cursor)
Posted Last updated
.
Post marked as solved
3 Replies
634 Views
If I want to refer to the actual window (where I write the code) I would do view.window or self.view.window. For instance:view.window?.title = "new title"But if I am in another place, for instance, in the AppDelegate.swift how do I refer to a specific window? For instance, I tried and it does not work:ViewController.title = "new title"(macOS and Swift)(I am quite new with Swift. Sorry if my question is innocent but I cannot find the answer anywhere. I would appreciate any orientation)
Posted Last updated
.
Post not yet marked as solved
1 Replies
479 Views
(Swift and macOS)I have a window that I would like to be in all the spaces. One option would be that the window could change when the user goes to another space.I could find that in the documentation: https://developer.apple.com/documentation/appkit/nswindow/1419707-isonactivespaceI am not sure how to implement it. This is what I tried. It does not work: override func viewDidLoad() { super.viewDidLoad() self.view.window?.collectionBehavior = NSWindow.CollectionBehavior.canJoinAllSpaces self.view.window?.collectionBehavior = NSWindow.CollectionBehavior.moveToActiveSpace }Should I do anything else, anything different?Thank you
Posted Last updated
.
Post not yet marked as solved
4 Replies
634 Views
How to have a window without the window bar? I mean without the bar, the title and the buttons on the top left.I know that I can do that in the storyboard but I want to do it programmatically and with SwiftWhat I have tried: override func viewWillAppear() { super.viewWillAppear() // view.window?.titlebarAppearsTransparent = true // It makes the bar transparent but I still see the buttons }
Posted Last updated
.
Post not yet marked as solved
3 Replies
443 Views
How to position the window of the app from the beginning, when the app launches?This works well if I put in a button:@IBActionfunc test(_ sender: NSButton) { view.window?.setFrame(NSRect(x:0,y:0,width:500,height:500), display: true) }But it does not work if I put in the viewDidLoad or ViewDidAppear:overridefunc viewDidLoad() { super.viewDidLoad() view.window?.setFrame(NSRect(x:0,y:0,width:500,height:500), display: true) }
Posted Last updated
.
Post marked as solved
2 Replies
510 Views
var arrayDictionaries: [[String: Any]] = [["key1": 1.1, "key2": [ "Height": 427, "Width": 655, "X": 1025, "Y": 384 ], "key3": "value3.1"], ["key1": "value1.2", "key2": "value2.2", "key3": "value3.2"]]How to get the value of Height in this code?I can get for instance the value of the key1 of the first dictionary:let key1 = arrayDictionaries[0]["key1"]print (key1)But I do not know how to reach ay of the values of the next level, like Height. This gives me the error "Value of type 'Any' has no subscripts"let key2 = arrayDictionaries[0]["key2"]["Height"]print (key2)
Posted Last updated
.