Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

swift share with

import UIKit
class ViewController: UIViewController {

    // share text
    @IBAction func shareTextButton(_ sender: UIButton) {

        // text to share
        let text = "This is some text that I want to share."

        // set up activity view controller
        let textToShare = [ text ]
        let activityViewController = UIActivityViewController(activityItems: textToShare, applicationActivities: nil)
        activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash

        // exclude some activity types from the list (optional)
        activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook ]

        // present the view controller
        self.present(activityViewController, animated: true, completion: nil)

    }

    // share image
    @IBAction func shareImageButton(_ sender: UIButton) {

        // image to share
        let image = UIImage(named: "Image")

        // set up activity view controller
        let imageToShare = [ image! ]
        let activityViewController = UIActivityViewController(activityItems: imageToShare, applicationActivities: nil)
        activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash

        // exclude some activity types from the list (optional)
        activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook ]

        // present the view controller
        self.present(activityViewController, animated: true, completion: nil)
    }

}
Comment

PREVIOUS NEXT
Code Example
Swift :: change from Date to String swift 5 
Swift :: swift stackview content inset 
Swift :: swift change navigation bar color 
Swift :: swift first where 
Swift :: swift set view z order front 
Swift :: how to remove background color for uibutton swift 
Swift :: presentviewcontroller must be set swift google login 
Swift :: how to swift pie chart quartzcore framework 
Swift :: swift ui function with return value 
Swift :: get request swift 
Swift :: swift ui font color 
Swift :: uicolor from hex swift 
Swift :: alamofire failure response body 
Swift :: button in swiftui 
Swift :: swift doc comments 
Swift :: textchange in textview swift 
Swift :: How to set back button text in Swift 
Swift :: show back button in navbar swift 
Swift :: struct vs enum swift 
Swift :: swiftui textfield height 
Swift :: how to low case string swift 
Swift :: Swift Closure That Returns Value 
Swift :: swift iterate through string 
Swift :: swiftui foreach enum not all cases 
Swift :: swift extension Array of element 
Swift :: Swift guard-let Statement 
Swift :: value to value in sum 
Swift :: send receive udp swift 
Swift :: how to create button action programmatically in ios 
Swift :: uiviewcontroller title color 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =