Skip to content

Instantly share code, notes, and snippets.

View leoiphonedev's full-sized avatar

Aman Aggarwal leoiphonedev

View GitHub Profile
UIImage *instaImage = [UIImage imageNamed:@"imagetoShare.png"];
NSString* imagePath = [NSString stringWithFormat:@"%@/image.igo",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) lastObject]];
[[NSFileManager defaultManager] removeItemAtPath:imagePath error:nil];
[UIImagePNGRepresentation(instaImage) writeToFile:imagePath atomically:YES];
@leoiphonedev
leoiphonedev / UIDocumentInteractionController.m
Last active July 12, 2017 10:57
Share image to instagram using objective C in iOS app development
UIImage *instaImage = [UIImage imageNamed:@"imagetoShare.png"];
NSString* imagePath = [NSString stringWithFormat:@"%@/image.igo",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES) lastObject]];
[[NSFileManager defaultManager] removeItemAtPath:imagePath error:nil];
[UIImagePNGRepresentation(instaImage) writeToFile:imagePath atomically:YES];
@leoiphonedev
leoiphonedev / UIDocumentInteractionController.swift
Last active April 11, 2018 17:28
Sharing image to Instagram using Swift language
let image = UIImage(named: "imageToShare")
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String
let checkValidation = FileManager.default
let getImagePath = paths.appending("image.igo")
try? checkValidation.removeItem(atPath: getImagePath)
let imageData = UIImageJPEGRepresentation(image!, 1.0)
try? imageData?.write(to: URL.init(fileURLWithPath: getImagePath), options: .atomicWrite)
var documentController : UIDocumentInteractionController!
documentController = UIDocumentInteractionController.init(url: URL.init(fileURLWithPath: getImagePath))
documentController.uti = "com.instagram.exclusivegram"
@leoiphonedev
leoiphonedev / UIDocumentInteractionControllerTutorialViewController.h
Last active January 18, 2017 06:18
Creating inastance of UIDocumentInteractionController
@property(nonatomic,strong) UIDocumentInteractionController *_docController;
@leoiphonedev
leoiphonedev / UIDocumentInteractionControllerTutorialViewController.m
Created January 18, 2017 06:22
UIDocumentInteractionController tutorial for sharing image
UIImage *instaImage = [UIImage imageNamed:@"imageToShare.png"];
NSString* imagePath = [NSString stringWithFormat:@"%@/image.png",[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]];
[[NSFileManager defaultManager] removeItemAtPath:imagePath error:nil];
[UIImagePNGRepresentation(instaImage) writeToFile:imagePath atomically:YES];
self._docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:imagePath]];
[self._docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
@IBOutlet var pageControl: UIPageControl?
@IBOutlet var scrollView: UIScrollView?
var scrollWidth : CGFloat = UIScreen.main.bounds.size.width
var scrollHeight : CGFloat = UIScreen.main.bounds.size.height
@IBAction func changePage(){
}
class ViewController: UIViewController {
@IBOutlet var pageControl: UIPageControl?
@IBOutlet var scrollView: UIScrollView?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func changePage(){
scrollView!.scrollRectToVisible(CGRectMake( scrollWidth * CGFloat ((pageControl?.currentPage)!), 0, scrollWidth, scrollHeight), animated: true)
}
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
setIndiactorForCurrentPage()
}
func setIndiactorForCurrentPage() {
let page = (scrollView?.contentOffset.x)!/scrollWidth
pageControl?.currentPage = Int(page)
}