• May
  • 16
  • 2015

Want to add image sharing to social media button? Or having trouble in your code for picture sharing button in iOS application?

Don’t worry!

Here is the steps and code to add picture share button:

Share an image to available social media with UIActivityViewController in iOS

Steps:

1. Add a button in view controller from your storyboard

2. Create a button method for your share button as follows:

-(IBAction)btnShareClick:(id)sender
{
UIButton *shareButton = (UIButton*)sender;
//image from project.
UIImage *imgShare=[UIImage imageNamed:@“star.png"];
NSArray *Items = [NSArray arrayWithObjects: imgShare, nil];
UIActivityViewController *ActivityView =[[UIActivityViewController alloc]initWithActivityItems:Items applicationActivities:nil];

// Exclude following activities.
NSArray *excludedActivities = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,UIActivityTypeAirDrop];
ActivityView.excludedActivityTypes = excludedActivities;
ActivityView.popoverPresentationController.sourceView= shareButton;

[self presentViewController:ActivityView animated:YES completion:nil];
}

3. Map above method to Touchup inside event of that button

You are done. Enjoy Sharing !!

Want help in iOS App Development? Hire Us!!

hire iphone app developers

Ravi Makhija

Ravi Makhija

A writer, an Entrepreneur. Curious about the internet of everything. Interested in the cutting edge landscape of mobile apps and SAAS products. Blogs for Guru Technolabs - A Mobile App Development Company.

Popular Blogs

recent-blog-image

Among the many digital tools that are being used with…

recent-blog-image

This question is most searched question in google. It is…

recent-blog-image

When you are using WPML in wordpress at that time…

recent-blog-image

Method for linking pages that aren't in a Site Menu…

recent-blog-image

Manier times we come across requirement like fetching/getting content from…

Let's Discuss a Project

Please share your unique idea or project requirement with us, our business concern person will get back to you with further details.