As I understand you want to implement iOS native sharing functionality. Here is an example of implementation:
- (void)shareButtonPressed {
// 1
// If you want to use UIImage, make sure you have image with that name, otherwise it will crash.
NSArray *activityItems = @[@"Message to share", [UIImage imageNamed:@"imageToShare"]];
// 2
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
// 3
activityViewController.excludedActivityTypes = @[UIActivityTypeCopyToPasteboard, UIActivityTypeAirDrop, UIActivityTypeAssignToContact, UIActivityTypeAddToReadingList, UIActivityTypePrint, UIActivityTypeSaveToCameraRoll, UIActivityTypeMessage, UIActivityTypeMail];
// 4
[activityViewController setCompletionHandler:^(__unused NSString *activityType, __unused BOOL completed){
// Custom completion implementation
}];
[self presentViewController:activityViewController animated:YES completion:NULL];
}
Description:
- Prepare activity items which you want to share such string, image, URL.
- Initialize activity view controller with the items you want to share + custom activities (only if needed). Custom activities means that you will create your own buttons using UIActivity with own actions, images, titles (more info here). For example, implement sharing to a third party app which does not have share extension.
- Here you can specify excluded activity types. In this example I have removed everything such as copy, airdrop and etc.
- In completion block you can see which activityType was selected and whether user cancelled or not.
More information on UIActivityViewController can be found here.
Regarding second part of your question about UIBarButtonItem. UIBarButtonItem can be initialised with custom title using this:
UIBarButtonItem *shareButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Share" style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed)];
self.navigationItem.rightBarButtonItem = shareButtonItem;
Be aware that UIBarButtonItem has UIBarButtonItemStyle which you can change. UIBarButtonItemStylePlain (will create a button with a regular font) and UIBarButtonItemStyleDone (will create a button with a bold font).