Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show the share button in Mountain Lion?

Mountain Lion offers a built-in sharing button that reveals a menu of sharing services appropriate for the app:

Share button in Safari 6.0

How can I insert it in my app?

like image 485
Dev Avatar asked Aug 05 '12 08:08

Dev


2 Answers

In Swift, I've used this:

extension NSSharingService {
    class func shareContent ( content: [AnyObject], button: NSButton ) {
        let sharingServicePicker = NSSharingServicePicker (items: content )

        sharingServicePicker.showRelativeToRect(button.bounds, ofView: button, preferredEdge: NSRectEdge.MaxY)
    }
}
like image 63
Rene Rosendahl Avatar answered Nov 19 '22 15:11

Rene Rosendahl


To add the share button on Mountain Lion:

1) Add a NSButton called, for example, shareButton.

2) Add the standard image for this button:

[shareButton setImage:[NSImage imageNamed:NSImageNameShareTemplate]];
[shareButton sendActionOn:NSLeftMouseDownMask];

3) Into the "on click action", present the NSSharingServicePicker:

NSSharingServicePicker *sharingServicePicker = [[NSSharingServicePicker alloc] initWithItems:urls];
sharingServicePicker.delegate = self;

[sharingServicePicker showRelativeToRect:[sender bounds]
                                          ofView:sender
                                   preferredEdge:NSMinYEdge];

4) Eventually, implement the NSSharingServicePickerDelegate methods to customize the picker’s available services.

like image 23
Dev Avatar answered Nov 19 '22 15:11

Dev