[Swift] Setting the behavior when the Share button is pressed

You can almost copy and paste

-It should be. However, the destination to share is not specified in this article (Instagram, Twitter, etc.). I think it's familiar that the modal comes out from the bottom when you press the Share button, but it's mainly the setting.

Implementation

ViewControlloer.swift


  @IBAction func share(_ sender: Any) {
    
    //It will be shared with SNS services etc. at the same time as the text here
    let text = "#Service name"
    //Compress images to share in jpeg format. The compression rate is arbitrary. The more you apply, the rougher the image, but the faster the processing
    let image = backImageView.image?.jpegData(compressionQuality: 0.5)
    //Define what you want to share as an item. I'm asked for a type, but it's not any type, so Any
    let item = [text,image as Any]
    //Screen transition (modal coming out from the bottom) settings
    let activitiyVC = UIActivityViewController(activityItems: item, applicationActivities: nil)
    //Screen transition
    self.present(activitiyVC, animated: true, completion: nil)
  }

Recommended Posts

[Swift] Setting the behavior when the Share button is pressed
[swift] How to control the behavior when the back button of NavigationBar is pressed
[Android] Easily control the event when the Back button is pressed in Fragment
Change the processing when the button on RecyclerView is pressed for each list
Behavior when each is executed in the reverse order Range
[Swift] Get the timing when the value of textField is changed
When the bean class name is duplicated
When UITextView is not displayed (Swift, Xcode)
Be careful when setting the class name when creating a document-based app in Swift
Behavior when wild card (**) is specified in ruby
When the project is not displayed in eclipse
[Unity] When implementing iOS native plugin with Swift, the setting method will change around 2019.3.