Cocoa Image Picker Popover - macos

Several places in OS X (in this example, the Users & Groups pane in System Preferences) have circular image views that allow the user to either drag in an image, like in an editable NSImageView but also allow them to click to show a popover that allows various other choices of image sources.
I have checked the ImageKit framework, but the only thing I found similar is the image taking sheet.
How can I make use of this feature in my own Cocoa applications? I'd imagine it is implemented in some standard framework—but any pointers on implementing something like this would be quite appreciated.

You will have to go down the custom control root as this is not available as a stand alone control.
However you have all the prerequisites.
The circular image view
There a several ways to implement this. You could try using a standard Cocoa button and customise as needed. Although it might just be easier to build from scratch by subclassing NSView. This was you can avoid all the NSCell stuff. I would do the latter.
The popover
Roll your own master-details type view controller to be displayed as the popover's content. In the left have a NSTableView (the master), the right have a NSCollectionView (the details). Below the collection view add some buttons.

Related

Build a Cocoa UI for OSX

I'm trying to build a UI which look like this:
I'm using a storyboard with Xcode but I don't know how to start. I think a need different view in the window to manage button, text and tree but I don't know I to do it. I have try to use a split view but it gave me only 2 views instead of 3.
Any help in Cocoa and storyboard is welcome.
Thanks
Can't see where you'd want to use an NSSplitView but the UI you're attemting to create is trivial -
A plain NSWindow with the toolbar items configured as per your screenshot.
An NSOutlineView for the tree view with the three columns,
the content border of the window sized accordingly to make room for the label you intend to put at the bottom of the window.
As mentioned in the comments one way to populate the outline view would be to use an NSTreeController and Cocoa bindings. That's probably the only slightly more complicated bit about this UI..

Advice needed for developing multiple window Mac application

I’ve been reading through several books on Mac development, but cannot find the information I’m looking for.
The books all describe how to make floating windows or panes, but never mention how to make them all in one window. A simplified example of what I’m looking to create is shown below:
Basically, there will be three windows; A selector window with radio buttons to choose which NSDocument is currently being used, a window underneath that with buttons that show different windows to the right that allow viewing and manipulation of certain data.
For a example, each NSDocument may have a color value that can be set in the window shown by clicking view A, and some text strings that can be set in the window shown by clicking view B.
So the questions are:
Is it appropriate to use a single NSDocument sub-class for each Doc #1 and Doc #2?
Which classes should I use to set up the application as shown? NSWindowController? NSWindow? NSPanel?
I’m only looking for guidance on what to read up on, so any pointers are appreciated.
EDIT:
To clarify this further, I want to have a table view where the buttons are (View A & B), and by clicking them they will cause the other window/view to change it's contents.
It's like the split view in the iPad settings application, there is a table view on the left, and when it's pressed the right side changes.
The radio buttons are there only to illustrate that I want more than one Document. I'm guessing I need more than one to handle this? Or perhaps I should place them all in a single NSDocument? Somehow that doesn't seem right.
To achieve what you want you need one window (NSWindow), one window controller and various views each with their own view controller. There are several ways you could set this up, all depending on your requirements:
You'd have at least 3 views (instances of NSView): one for the selection of the document class, one for the view selection and one for the content. Each view is controlled by a view controller (instance of NSViewController). Additionally you can opt to wrap the views in split views (NSSplitView) so your user can resize the real estate available to each view.
You have one window with a window controller. If you choose a Document based app template in Xcode, Xcode will generate a subclass of NSDocument which you can use as your window controller (or choose to use Core Data and Xcode will generate a subclass of NSPersistentDocument with all bells and whistles you need to access Core Data for document persistency).
So to come back to your questions:
1: Yes, but depending on your requirements. If Doc #1 is a completely different thing than Doc #2 than you might need to re-evaluate. For example Doc #1 might have completely different persistent requirements than #2.
2: There's no single scenario here, but one that worked for me: Take the project template for a document based app (with or without Core Data). Use the generated subclass of NSDocument (or NSPersistentDocument) as your window controller. Use NSView to implement the views in your window where each view is managed by its own controller, which is an instance of NSViewController.
I know this is an old question, but a way to do it how you want would be to use: ContainerViews and set their embed segue to be the view controllers you want.

Dragging from and to NSButton

I am trying to write an app. that will allow the user to drag from an NSButton to another. When dropped I would like the Title to be dropped onto the button.
I cannot find a way to make NSButton draggable. Is it possible?
First a warning: this sounds like it would be confusing to a user. Buttons are intended to emulate buttons in the real world. You push them rather than drag them around.
Having said that, it's certainly possible to do in a subclass of NSButton.
Drag source
Implement the dragging source method draggingSourceOperationMaskForLocal:. Sounds like you're copying the title, so you may want to use NSDragOperationCopy.
Call dragImage:at:offset:event:pasteboard:source:slideBack: in your mouseDragged: method. Use the drag pBoard ([NSPasteboard pasteboardWithName:NSDragPboard]) and copy your button title into it. For the image you can draw your button into an NSImage and use that as the drag image, or you might use an icon or even just the title.
Drag destination
Register your custom button to be able to accept the title string using registerForDraggedTypes:.
Implement the drag destination methods draggingEntered: and performDragOperation: to return appropriate values. There are several other methods including draggingUpdated: and draggingExited: among others that you can use to provide visual feedback.
There's lots of info out there on implementing drag & drop. Read Apple's docs: Drag & Drop Programming Topics and Pasteboard Programming Guide

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.

How do you create a Keynote-like interface in Cocoa and IB?

the app I want to create will have an interface very like Keynote, with a list of pages on the left and one page in full on the right. These kinds of interfaces are very common yet I don't know how to do them in Interface Builder.
Are there any ready-made components? Apple doesn't offer any, afaik. Or does every developer recreate this from scratch?
I only need a general idea or tutorial, no finished code.
Thanks in advance!!
If you're referring to a scrollable list of same-size thumbnails, use NSCollectionView / NSCollectionViewItem. Should be very easy: the item would just display a thumbnail image based on your document editor view's current state. In 10.6, it got some drag and drop support, if I remember correctly from WWDC '09, so you can drag-reorder your pages this way, too.
For the editor side, the collection view would only work if all your pages are the same size, as it doesn't allow for variable-sized items. If all your "pages" are the same size, though, the collection view should actually work for this too.

Resources