Monday, 1 June 2015

How to create UIActivityViewController Swift IOS Tutorial



UIActivityViewController in Swift tutorial

UIActivityViewController using swift is similar to as we create in objective C , you can read it how to create UIActivityViewController in objective C from  here. This post will give you an example of sharing image through UIActivityViewController in Swift.

Create a new project and select swift as development language. Add an image to your project and replace index.jpg with your image name. Open ViewController.swift and add below code to it.


 @IBAction func clickAction (sender:UIButton)
     {
         var image = UIImage(named:"index.jpg")!;
         var objectToShare = [image]
        
         let activityViewController = UIActivityViewController(activityItems:objectToShare,  applicationActivities: nil)
        activityViewController.excludedActivityTypes  =  [UIActivityTypePostToWeibo,UIActivityTypePostToVimeo]
        self.presentViewController(activityViewController, animated: true, completion:nil)      
    }


Open storyBoard and drag UIButton to it. Connect the IBAction to it and compile and run it.

in this post we learned about how to create UIActivityViewController in swift.

If you are  having any problems then feel free to ask.


No comments:
Write comments