Tuesday, 22 January 2013

Screen Shot

Screen Shot
-(IBAction)screenShot:(id)sender
{
          CGRect screenRect = [[UIScreen mainScreen] bounds];
    UIGraphicsBeginImageContext(screenRect.size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    [[UIColor blackColor] set];
    CGContextFillRect(ctx, screenRect);
    [self.view.layer renderInContext:ctx];
  UIImage *screenImage =         UIGraphicsGetImageFromCurrentImageContext();
    UIImageWriteToSavedPhotosAlbum(screenImage, nil, nil, nil);
    UIGraphicsEndImageContext();
}

Border Color Of image type




 UIImage *green = [UIImage imageNamed:@"imageName.png"];
 UIImageView *anImageView=[[UIImageView alloc]initWithFrame:CGRectMake(x,y,w,h)];
[self.view addSubview:anImageView];
    [anImageView.layer setBorderWidth:15.0f];
    [anImageView.layer setBorderColor:[UIColor colorWithPatternImage:green].CGColor];
    [anImageView.layer setShadowRadius:5.0f];
    [anImageView.layer setShadowOpacity:.85f];
    [anImageView.layer setShadowOffset:CGSizeMake(1.0f, 2.0f)];
    [anImageView.layer setShadowColor:[[UIColor blackColor] CGColor]];
    [anImageView.layer setShouldRasterize:YES];
    [anImageView.layer setMasksToBounds:NO];
    
Note : import <QuartzCore/QuartzCore.h> and framework

nil and NULL

In Cocoa both of them are typedef to zero. nil is an object pointer, whereas NULL is a c pointer.  If you want to set char * to 0 then you would set it to NULL and if you want to set a view controller to 0 then you would set it to nil. Cocoa also gives us another typedef  called “Nil” (notice the case) which is class pointer. Now you know when to use the correct null pointer.

PayPal SDK for iOS


PayPal SDK for iOS


Another day another dollar. After spending half a day, well I should say wasting half a day I've finally figured out how to add PayPal's SDK for iOS. I'm currently using XCode 4.

I will break it down into steps so hopefully this will help others!



1.) SDK Download.
- First you have to download the PayPal iOS SDK from here.

2.) "Adding the Files"
- Control Click on your project.xcode file and chose "Add files to project" (or chose File->"Add files to Project").
- Navigate to where you had saved your downloaded PayPal SDK on disk.
- You will find a folder named "Library" which contains 11 header files, as well as a static library named "libPayPalMPL.a".
- Select all of these files and check the "Copy items into destination group's folder (if needed) check box.
- Now before you build your project you have to add additional libraries. 
- Navigate to your Link Binary With Libraries within your project target and add the following Libraries.

  • Security.framework

  • libxml2.dylib

  • libz.dylib

  • 3.) #import "PayPal.h"
    - Now that you have everything added properly you have to #import "PayPal.h" and follow the documentation provided from PayPal.

    4.) Build your project and you will be ready to go!

    Hopefully this helps someone else out. I had searched on google for quite sometime and didn't really find anything helpful. Happy Coding!

    Crop Images

    Crop the image


    //Croping start from x=0; y=0; and till width=125 and height=128;

    UIImage *image =imageView.image;
    CGRect cropRect = CGRectMake(0, 0, 125,128);
    CGImageRef imageRef = CGImageCreateWithImageInRect([image CGImage], cropRect);
    [imageView setImage:[UIImage imageWithCGImage:imageRef]]; 
    CGImageRelease(imageRef); 
    
    
    Mask Image
    
    
    - (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage {
     
     CGImageRef maskRef = maskImage.CGImage; 
     
     CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef),
      CGImageGetHeight(maskRef),
      CGImageGetBitsPerComponent(maskRef),
      CGImageGetBitsPerPixel(maskRef),
      CGImageGetBytesPerRow(maskRef),
      CGImageGetDataProvider(maskRef), NULL, false);
     
     CGImageRef masked = CGImageCreateWithMask([image CGImage], mask);
     return [UIImage imageWithCGImage:masked];
     
    }

    Animation


    1 ->

    [viewContent.layer addAnimation:[self getShakeAnimation] forKey:@"transform.scale"];
    - (CAAnimation*)getShakeAnimation { 
        CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
    
        animation.values = [NSArray arrayWithObjects:
                            [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_2, 0.0f, 1.0f, 0.0f)],
                            [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI, 0.0f, 0.0f, 0.0f)],
                            [NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI * 2, 0.0f, 1.0f, 0.0f)],nil];
    
     animation.duration = 0.8f;
     animation.delegate = self;
    
    
        return animation;
    }
     

    2 -> animate view from bottom to top

    
    
    -(void)makeAnimation
    {
        CGRect optionsFrame = {0,480,320,480};
        userNameEmailView.frame = optionsFrame;
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1];
        [self.view addSubview:userNameEmailView];
        //optionsFrame.origin.x -= optionsFrame.size.width;
        optionsFrame.origin.y -= optionsFrame.size.height;
        userNameEmailView.frame = optionsFrame;
        [UIView commitAnimations];
    }
    
    

    3 -> Shake the view like error is generating

    
    
    -(void)shakeTheView
    {    
        CABasicAnimation *shake = [CABasicAnimation animationWithKeyPath:@"position"];
        [shake setDuration:0.1];
        [shake setRepeatCount:2];
        [shake setAutoreverses:YES];
        [shake setFromValue:[NSValue valueWithCGPoint:
                             CGPointMake(searchByCountryView.center.x - 15,searchByCountryView.center.y)]];
        [shake setToValue:[NSValue valueWithCGPoint:
                           CGPointMake(searchByCountryView.center.x + 15, searchByCountryView.center.y)]];
        [searchByCountryView.layer addAnimation:shake forKey:@"position"];
    }
    
    

    4 . -> Spin your view,best for loading type image

    
    
    - (void)spinTheView
    {
        [CATransaction begin];
        [CATransaction setValue:(id)kCFBooleanTrue forKey:kCATransactionDisableActions];
        CGRect frame = [searchByCountryView frame];
        searchByCountryView.layer.anchorPoint = CGPointMake(0.5, 0.5);
        searchByCountryView.layer.position = CGPointMake(frame.origin.x + 0.5 * frame.size.width, frame.origin.y + 0.5 * frame.size.height);
        [CATransaction commit];
    
        [CATransaction begin];
        [CATransaction setValue:(id)kCFBooleanFalse forKey:kCATransactionDisableActions];
        [CATransaction setValue:[NSNumber numberWithFloat:2.0] forKey:kCATransactionAnimationDuration];
    
        CABasicAnimation *animation;
        animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
        animation.fromValue = [NSNumber numberWithFloat:0.0];
        animation.toValue = [NSNumber numberWithFloat:2 * M_PI];
        animation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
        animation.delegate = self;
        [searchByCountryView.layer addAnimation:animation forKey:@"rotationAnimation"];
    
        [CATransaction commit];
    }
    
    

    3 -> Load the view From left side

    CATransition *animation = [CATransition animation]; [[self navigationController] pushViewController:elementController animated:NO]; [animation setDuration:0.45]; [animation setType:kCATransitionPush]; [animation setSubtype:kCATransitionFromLeft]; [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]]; [[elementController.view layer] addAnimation:animation forKey:@"SwitchToView1"];