Sunday 10 November 2013

Reload UITableView with animation

[tableView reloadData];
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromBottom];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[animation setFillMode:kCAFillModeBoth];
[animation setDuration:.3];
[[tableView layer] addAnimation:animation forKey:@"UITableViewReloadDataAnimationKey"];    

Thursday 7 November 2013

Checking for iPad or iPhone

if ([[UIDevice currentDevice].model rangeOfString:@"iPad"].location!=NSNotFound)
    {
        //ipad
    }
    else
    {
       //iphone
    }

Wednesday 6 November 2013

IOS UIButtion with animated gif Image

UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:    
                               [UIImage imageNamed:@"image1.png"],
                               [UIImage imageNamed:@"image2.png"],
                               [UIImage imageNamed:@"image3.png"],
                               [UIImage imageNamed:@"image4.png"], nil];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[yourButton addSubview: animatedImageView];

Friday 1 November 2013

JSON string From NSDictionary

NSDictionary *jsondict;

NSData *jsonData=[NSJSONSerialization dataWithJSONObject:jsondict options:NSJSONWritingPrettyPrinted error:Nil];

NSString *jsonStr=[[NSString alloc]initWithData: jsonData encoding:NSUTF8StringEncoding];


 jsonStr =[jsonStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

Monday 28 October 2013

Animated Images In UIImageView

UIImageView* animatedImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
animatedImageView.animationImages = [NSArray arrayWithObjects:    
                               [UIImage imageNamed:@"image1.png"],
                               [UIImage imageNamed:@"image2.png"],
                               [UIImage imageNamed:@"image3.png"],
                               [UIImage imageNamed:@"image4.png"], nil];
animatedImageView.animationDuration = 1.0f;
animatedImageView.animationRepeatCount = 0;
[animatedImageView startAnimating];
[self.view addSubview: animatedImageView];

Tuesday 8 October 2013

Blur effect for imge using Core Image

Add CoreImge.framework

UIImage *theImage = [UIImage imageNamed:@"Sample.png"];

    //create our blurred image
    CIContext *context = [CIContext contextWithOptions:nil];
    CIImage *inputImage = [CIImage imageWithCGImage:theImage.CGImage];

    //setting up Gaussian Blur (we could use one of many filters offered by Core Image)
    CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
    [filter setValue:inputImage forKey:kCIInputImageKey];
    [filter setValue:[NSNumber numberWithFloat:15.0f] forKey:@"inputRadius"];
    CIImage *result = [filter valueForKey:kCIOutputImageKey];
    //CIGaussianBlur has a tendency to shrink the image a little, this ensures it matches up exactly to the bounds of our original image
    CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]];

self.imageView.image=[UIImage imageWithCGImage:cgImage];

Friday 27 September 2013

How To Create a PDF with Quartz 2D

//*****************< Make PDF path >******************
    NSString* fileName = @"Test.PDF";
    NSArray *arrayPaths =
    NSSearchPathForDirectoriesInDomains(
                                        NSDocumentDirectory,
                                        NSUserDomainMask,
                                        YES);
    NSString *path = [arrayPaths objectAtIndex:0];
    NSString* pdfFileName = [path stringByAppendingPathComponent:fileName];

//*****************< PDF Begins >**********************
    UIGraphicsBeginPDFContextToFile(pdfFileName, CGRectZero, nil);
    // Mark the beginning of a new page.
    UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);

//*****************< Draw Image >**********************
    UIImage* logo = [UIImage imageNamed:@"sample.png"];

    NSLog(@"%f",logo.size.height);
    CGRect frame = CGRectMake(20, 100, 250, 250);

    [logo drawInRect:frame];


//*****************< Draw Line >***********************
    CGPoint from = CGPointMake(300, 100);
    CGPoint to = CGPointMake(300, 300);


    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetLineWidth(context, 5.0);

    CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();

    CGFloat components[] = {0.0, 1, 0.8, 0.8};

    CGColorRef color = CGColorCreate(colorspace, components);

    CGContextSetStrokeColorWithColor(context, color);


    CGContextMoveToPoint(context, from.x, from.y);
    CGContextAddLineToPoint(context, to.x, to.y);

    CGContextStrokePath(context);
    CGColorSpaceRelease(colorspace);
    CGColorRelease(color);


//****************< Write Text >***********************
    NSString* textToDraw = @"Hello World";
    CFStringRef stringRef = (__bridge CFStringRef)textToDraw;
    // Prepare the text using a Core Text Framesetter
    CFAttributedStringRef currentText = CFAttributedStringCreate(NULL, stringRef, NULL);
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(currentText);

    CGRect frameRect = CGRectMake(20, 0, 300, 50);
    CGMutablePathRef framePath = CGPathCreateMutable();
    CGPathAddRect(framePath, NULL, frameRect);

    // Get the frame that will do the rendering.
    CFRange currentRange = CFRangeMake(0, 0);
    CTFrameRef frameRef = CTFramesetterCreateFrame(framesetter, currentRange, framePath, NULL);
    CGPathRelease(framePath);

    // Get the graphics context.
    CGContextRef currentContext = UIGraphicsGetCurrentContext();

    // Put the text matrix into a known state. This ensures
    // that no old scaling factors are left in place.
    CGContextSetTextMatrix(currentContext, CGAffineTransformIdentity);

    // Core Text draws from the bottom-left corner up, so flip
    // the current transform prior to drawing.
    CGContextTranslateCTM(currentContext, 0, 100);
    CGContextScaleCTM(currentContext, 1.0, -1.0);

    // Draw the frame.
    CTFrameDraw(frameRef, currentContext);

    CFRelease(frameRef);
    CFRelease(stringRef);
    CFRelease(framesetter);



//**************< PDF Ends >***************************
    // Close the PDF context and write the contents out.
    UIGraphicsEndPDFContext();