The problem:

You want to implement a share button that takes a screenshot from your app and let’s users share it to social media.

Caveats:

  • You want to create a custom image by creating a custom UIViewController.
  • You don’t want the UIViewController to show.
  • You want to show a nice preview of the image that you’ll share.

You cant find the complete project on GitHub here.

Let’s get started with a clean project.

Project setup

Let’s start with a clean project. Add a share button to the default view controller. For the button image, you can choose square.and.arrow.up to make it look like a native share button.

Image for post

Add a new view controller which will produce the image to be shared. **Do not **add a segue from the old view controller to the new one — this will be done programmatically.

Image for post

#programming #ios #social-media #swift #swift-programming

Share to social media on iOS with UIActivityViewController
8.35 GEEK