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 / 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];
@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)
}
@leoiphonedev
leoiphonedev / example.h
Created January 18, 2017 10:30
Declaring our IBOutlets for pagecontrol and UIScrollView
@interface ViewController : UIViewController {
IBOutlet UIPageControl *pageControl;
IBOutlet UIScrollView *scrollView;
}
-(IBAction)changePage:(id)sender;
@end
@leoiphonedev
leoiphonedev / example.m
Created January 18, 2017 10:32
Creating pageview showing 3 images and adding them to scroll view
#define SCROLLWIDTH 279
- (void)viewDidLoad {
scrollView.contentSize=CGSizeMake(SCROLLWIDTH*3,
scrollView.frame.size.height);
scrollView.delegate = self;
for (int i =0; i<=3; i++) {
UIImageView *imageView = [[UIImageView alloc]initWithFrame:
CGRectMake(SCROLLWIDTH*i, 0, scrollView.frame.size.width,
scrollView.frame.size.height)];
if (i==0) {
@leoiphonedev
leoiphonedev / example.m
Created January 18, 2017 10:33
Creating IBAction for UIPageControl so that when user tap on UIPageControl it scroll to next page
#pragma mark changePage
-(IBAction)changePage:(id)sender
{
[scrollView scrollRectToVisible:CGRectMake(SCROLLWIDTH*pageControl.currentPage, scrollView.frame.origin.y, SCROLLWIDTH, scrollView.frame.size.height) animated:YES];
}