Creating gradient button bar in cocoa - cocoa

My question is almost exactly the same as this question, however the answer accepted (and only) answer was to use BWToolkit which is no longer an option for me because it isn't compatible with Xcode 4.
How can I create a similar bar in interface builder or programmatically, without BWToolkit?

You can look at the source code of BWToolkit. It uses a custom NSView subclass to do the drawing. Cocoa hasn't got a built-in control for this.
Alternatively, you can use BWToolkit, but just the parts you need (BWAnchoredButtonBar, BWSplitView, BWAnchoredButtonBar and the NSColor and NSView categories). You don't need to include the entire framework in your app.

Related

How does one display a new view controller in the same Mac window?

I'm fairly new to Mac development and am slightly confused by the new "storyboard" feature in Xcode 6. What I'm trying to do is segue from one view controller to another in the same window. As of right now, all the different NSViewControllerSegues present the view controller in a new window, be it a modal or just another window. What I'd like to do is just segue within the same window, much in the same way one would on iOS (though an animated transition is not crucial). How would this be achieved?
If you provide a custom segue (subclass of NSStoryboardSegue) you can get the result you are after. There are a few gotchas with this approach though:
the custom segue will use presentViewController:animator so you will need to provide an animator object
because the presented view is not backed by a separate Window object, you may need to provide it with a custom NSView just to catch out mouse events that you don't want to propagate to the underlying NSViewController's view
there's also a Swift-only glitch regarding the custom segue's identifier property you need to watch out for.
As there doesn't seem to be much documentation about this I have made a small demo project with custom segue examples in Swift and Objective-C.
I also have provided some more detail in answer to this question.
(Reviving this as it comes up as first relevant result on Google and I had the same problem but decided against a custom segue)
While custom segues work (at least, the code given in foundry's answer worked under Swift 3; it needs updating for Swift 4), the sheer amount of work involved in writing a custom animator suggests to me that their main use case is custom animations.
The simple solution to changing the content of a window is to create an NSWindowController for your window, and to set its contentViewController to the desired viewController. This is particularly useful if you are following the typical pattern of storyboards and instantiate a new ViewController instance every time you switch.
However.
The NSStoryboard documentation says, quite clearly in macOS, containment (rather than transition) is the more common notion for storyboards which led me to look again at the available tools.
You could use a container view for this task, which adds a NWViewController layer instead of the NSWindowController outlined above. The solution I've gone with is to use an NSTabViewController. In the attributes inspector, set the style to 'unspecified', then select the TabView and set its style to 'tabless'.
To change tabs programatically, you set the selectedTabViewItemIndexof your TabViewController.
This solution reuses the same instance of the ViewControllers for the tab content, so that any data entered in text fields is preserved when the user switches to the other 'tab'.
Simple way with no segues involved to replace the current view controller in the same window:
if let myViewController = self.storyboard?.instantiateController(withIdentifier: "MyViewController") as? MyViewController {
self.view.window?.contentViewController = myViewController
}

In MonoTouch, is it possible to mix standard Views and iPhoneOSGameViews?

Is it possible to have like a main menu based on a let's say a DialogViewController, and navigate to a OpenGL-ES based iPhoneOSGameView ?
Yes. You can even add multiple OpenGL ES views as subviews of a standard UIView.
Though you ask about iPhoneOSGameView specifically, I recommend considering GLKView available as of iOS 5. This provides some of the same features as the iPhoneOSGameView as well as some of the generated boilerplate around animation and CADisplayLink. It would also give you the option of creating the view in the Interface Builder, should you desire. Finally, it is provided by Apple to fill a similar role and, arguably, would be more aligned with future development.
I have done the reverse. In fact, MonoGame supports opening iPhoneOSGameView as the main view and displaying standard modal view controllers over top of it. This functionality is in the GamerServices section of XNA.
I think you should create a simple example, print a solid color in the game view and try presenting it over top of a standard controller.
I would think it would work fine.

Cocoa forControlEvents:WHATGOESHERE

In Cocoa/Objective-C if I have created a button programmatically, what do I put in for my control event?
[btnMakeChar addTarget:self action:#selector(makeChar:) forControlEvents:WHAT GOES HERE?];
In iOS you can write it like so forControlEvents: UIControlEventTouchUpInside
I can't find anything to show what I would use for just cocoa, not cocoa touch
I'm not sure if I understand you correctly, but if you're programming a Mac,
[theHappyButton setTarget:self];
[theHappyButton setAction:#selector(doStuff)];
it is two separate lines, rather than the one combined line of code on an iPhone.
I hope that is what you were after??
To find it in the doco: choose on the 10.6 doco (not iOS) and search on "setAction:". You'll see it in NSControl Class Reference. NSButton is of course a subclass of NSControl.
The method you're asking about does not exist in Cocoa, so nothing goes there. Cocoa controls have a single target with a single action, and either use a different addTarget:-type method for each kind of action or expect a delegate object that will handle all the events they generate.

Is it possible to design NSTableView cells using Interface Builder? (not for iOS apps)

Is it possible to design NSTableView cells using Interface Builder?
I know this is actually possible if your project is for iOS but somehow IB does not render the cell container if its for Mac OS X.
Im not sure if Amy gave that answer when this couldn't be done before, but this can be done quite easily on interface builder.
It can be done using view-based table view cells (instead of cell based) shown in the apple docs. There's is even a decent example you can download from the reference site.
No. The reason it's possible on iOS is because UITableViewCells inherit from UIView. Interface Builder lets you lay out views by putting other views within them.
On the desktop, for performance reasons from back when NextStep ran on 16mhz computers, NSCell does not inherit from NSView. A cell, on the Mac, does not have its own coordinate system or subview hierarchy, so it doesn't make sense to edit it in Interface Builder: you couldn't put other views within it!
So to make a custom cell, you need to draw everything with drawing functions such as CoreGraphics. You can't just drop in an NSImageView, you have to draw the image directly.

Cocoa : How to make a small toolbar like in Pages or Numbers?

Apples Application like Pages and Numbers always show an additional small Toolbar under the main Toolbar. Is there an object like this in the Interface Builder or do I have to build it from scratch?
I looked in the IB Library but found nothing so far.
You use NSSegmentedControl objects to do that, styled to Capsule. To achieve segmented controls with labels aligned underneath (which are clickable, like in Mail.app and Preview.app), you need to put them into toolbar button groups. That can't be done in IB. See this discussion in the Cocoa mailing list:
http://www.cocoabuilder.com/archive/cocoa/204390-capsule-style-toolbar-controls.html
There is no build-in control for that. You can take a look at the BWToolkit from Brandon Walkin. It has a lot of nice controls to build Apple-like applications. Maybe it can fit your needs...
It's just a simple view containing various controls. You could build most of it directly in Interface Builder. Just create an NSBox, give it a background color and then place "Mini"-sized controls in it.

Resources