How to show the share button in Mountain Lion?

后端 未结 3 1879
长发绾君心
长发绾君心 2021-02-03 12:06

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

\"Sh

3条回答
  •  一整个雨季
    2021-02-03 12:11

    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.

提交回复
热议问题