Powered By Blogger
Showing posts with label iPad Sample Code. Show all posts
Showing posts with label iPad Sample Code. Show all posts

Saturday, September 22, 2012

how to detect link in UIWebview?

Hi friends,
Again I'm here to share something new with you.. If you want to do some operations on URL click in UIWebview of iPhone/iPod/iPad then you need to use the below delegate method of UIWebview. You have to set WebViewDelegate in header file of your class.


#pragma mark-------------------------
#pragma mark WebView Delegate Method


- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = request.URL;
    NSString *urlString = url.relativeString;
    NSLog(@"%@",urlString);
    NSLog(@"%@",[request.URL lastPathComponent]);
    if (navigationType == UIWebViewNavigationTypeLinkClicked)
    {
        if([[urlString substringToIndex:5] isEqualToString:@"https"] || [[urlString substringToIndex:5] isEqualToString:@"http:"])
        {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString: urlString]];
        }
        else
        {
               // do your operation within Application
        }
        return NO;
    }
    return YES;
}

Hope you like this..

Thanks ,
Nilesh Prajapati

Thursday, July 5, 2012

how to draw images to PDF in iPhone sdk?

Hello friends,
I'm going to place PDF creation code for iOS SDK including images and textdraw. For this, you have to include "QuartzCore.framework" into your project.

Step 1: Include "QuartzCore.framework".

Step 2: Import "<QuartzCore/QuartzCore.h>" into your controller header file.

Step 3: Place below code into your class where you want to use it. You can change the parameters in your methods as per your requirement. You may change it any of the object.(Ex. UIView, UIImageView, etc...)


#pragma mark -
#pragma mark PDF Generation Code


-(IBAction)drawPdf:(id)sender
{
    [self writeImage:ImageView1 :1];
    [self writeImage:ImageView2 :2];
    [self writeImage:ImageView3 :3];
    [self drawImagesToPdf:ImageView1];
}


-(void)writeImage:(UIImageView *)btn:(NSInteger)tag
{
    CGRect screenRect = btn.frame;
    UIGraphicsBeginImageContext(screenRect.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [[UIColor whiteColor] set];
    CGContextFillRect(ctx, screenRect);
    [btn.layer renderInContext:ctx];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
   
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pngPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.png",tag]];
   
    [UIImagePNGRepresentation(newImage) writeToFile:pngPath atomically:YES];
}

-(void)drawImagesToPdf:(UIImageView *)button
{
CGSize pageSize = CGSizeMake(button.frame.size.width, button.frame.size.height*3+30);
  
    NSString *fileName = @"Demo.pdf";
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
    UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectMake(0, 0, button.frame.size.width, button.frame.size.height*3), nil);
  
    UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0.0, pageSize.width, button.frame.size.height), nil);
  
    NSString *name  = [NSString stringWithFormat:@"Unknown User];
    NSString *email = @"unknwon.hotmail.com";
    NSString *city=@"unknown";
    NSString *zip=@"unknown";
  
    [name drawInRect:CGRectMake(50.0, 50.0, button.frame.size.width-50.0, 20.0) withFont:[UIFont fontWithName:@"Verdana" size:15.0] lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentLeft];
  
    [email drawInRect:CGRectMake(50.0, 75.0, button.frame.size.width-50.0, 20.0) withFont:[UIFont fontWithName:@"Verdana" size:13.0] lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentLeft];
  
    [city drawInRect:CGRectMake(50.0, 100.0, button.frame.size.width-50.0, 20.0) withFont:[UIFont fontWithName:@"Verdana" size:13.0] lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentLeft];

    [zip drawInRect:CGRectMake(50.0, 125.0, button.frame.size.width-50.0, 20.0) withFont:[UIFont fontWithName:@"Verdana" size:13.0] lineBreakMode:UILineBreakModeWordWrap alignment:UITextAlignmentLeft];
  
    for (int i =1; i<=3; i++)
    {
        double currentHeight = 0.0;
        UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, currentHeight, pageSize.width, button.frame.size.height), nil);
        NSString *pngPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d.png", i]];
        UIImage *pngImage = [UIImage imageWithContentsOfFile:pngPath];
        [pngImage drawInRect:CGRectMake(0, currentHeight, pageSize.width, pngImage.size.height)];
    }
    UIGraphicsEndPDFContext();}

Feel free to ask if you have any issue using this code. 

Thanks & Regards,
Nilesh Prajapati

Wednesday, June 13, 2012

iPhone/iOS/iPad/Apple Sample Code

 Hi everyone,
Sample code is one of the most useful tools for learning about programming. Here's a collection of links I've found so far. Does anyone know of some other sources for iPhone sample code?

    •    Apple Sample Code: http://developer.apple.com/iphone/library/navigation/SampleCode.html
    •    Apps Amuck 31 days: http://appsamuck.com/
    •    Beginning iPhone Development: http://www.iphonedevbook.com/
    •    Chris Software: http://chris-software.com/index.php/dev-center/
    •    Dave DeLong's downloads: http://www.davedelong.com/downloads
    •    Delicious.com: http://delicious.com/alblue/iphonehttp://web.me.com/smaurice/AppleCoder/iPhone%5FOpenGL/Archive.htmlhttp://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-table-of.html
    •    iPhone Developer's Cookbook: http://code.google.com/p/cookbooksamples/downloads/list
    •    iPhone SDK source code: http://sites.google.com/site/iphonesdktutorials/sourcecode
    •    Joe Hewitt three20: http://joehewitt.com/post/the-three20-project/
    •    Stanford iPhone code: http://www.stanford.edu/class/cs193p/cgi-bin/downloads.php
    •    WiredBob (TabBar in Detail view): http://www.wiredbob.com/blog/2009/4/20/iphone-tweetie-style-navigation-framework.html
    •    BYU Cocoaheads : http://cocoaheads.byu.edu/
    •    Big Nerd Ranch: http://weblog.bignerdranch.com/
    •    Cocoa with love: http://cocoawithlove.com/
    •    Will Shipley: http://wilshipley.com/blog/
    •    mobile.tuts: http://mobile.tutsplus.com/
  
                                            •    Just sample code:
  
    •    Google Code: http://code.google.com/hosting/search?q=label%3Aiphone
    •    iPhone Cool Projects: http://www.apress.com/book/view/143022357x
    •    iPhone Game Projects: http://www.apress.com/book/downloadfile/4419
    •    Learn Objective-C on the Mac: http://www.apress.com/book/downloadfile/4175
    •    iCode Blog: http://icodeblog.com/
    •    Raywenderlich Tutorials: http://www.raywenderlich.com/
    •    OpenGLS: http://iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-table-of.html