Wednesday, March 13, 2013

Stop Image Rotation While Using Camera....by 90 degree


- (UIImage *)scaleAndRotateImage:(UIImage *)image {
    int kMaxResolution = 640
    
    CGImageRef imgRef = image.CGImage;
    
    CGFloat width = CGImageGetWidth(imgRef);
    CGFloat height = CGImageGetHeight(imgRef);
    
    
    CGAffineTransform transform = CGAffineTransformIdentity;
    CGRect bounds = CGRectMake(0, 0, width, height);
    if (width > kMaxResolution || height > kMaxResolution) {
        CGFloat ratio = width/height;
        if (ratio > 1) {
            bounds.size.width = kMaxResolution;
            bounds.size.height = roundf(bounds.size.width / ratio);
        }
        else {
            bounds.size.height = kMaxResolution;
            bounds.size.width = roundf(bounds.size.height * ratio);
        }
    }
    
    CGFloat scaleRatio = bounds.size.width / width;
    CGSize imageSize = CGSizeMake(CGImageGetWidth(imgRef), CGImageGetHeight(imgRef));
    CGFloat boundHeight;
    UIImageOrientation orient = image.imageOrientation;
    switch(orient) {
            
        case UIImageOrientationUp: //EXIF = 1
            transform = CGAffineTransformIdentity;
            break;
            
        case UIImageOrientationUpMirrored: //EXIF = 2
            transform = CGAffineTransformMakeTranslation(imageSize.width, 0.0);
            transform = CGAffineTransformScale(transform, -1.0, 1.0);
            break;
            
        case UIImageOrientationDown: //EXIF = 3
            transform = CGAffineTransformMakeTranslation(imageSize.width, imageSize.height);
            transform = CGAffineTransformRotate(transform, M_PI);
            break;
            
        case UIImageOrientationDownMirrored: //EXIF = 4
            transform = CGAffineTransformMakeTranslation(0.0, imageSize.height);
            transform = CGAffineTransformScale(transform, 1.0, -1.0);
            break;
            
        case UIImageOrientationLeftMirrored: //EXIF = 5
            boundHeight = bounds.size.height;
            bounds.size.height = bounds.size.width;
            bounds.size.width = boundHeight;
            transform = CGAffineTransformMakeTranslation(imageSize.height, imageSize.width);
            transform = CGAffineTransformScale(transform, -1.0, 1.0);
            transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);
            break;
            
        case UIImageOrientationLeft: //EXIF = 6
            boundHeight = bounds.size.height;
            bounds.size.height = bounds.size.width;
            bounds.size.width = boundHeight;
            transform = CGAffineTransformMakeTranslation(0.0, imageSize.width);
            transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);
            break;
            
        case UIImageOrientationRightMirrored: //EXIF = 7
            boundHeight = bounds.size.height;
            bounds.size.height = bounds.size.width;
            bounds.size.width = boundHeight;
            transform = CGAffineTransformMakeScale(-1.0, 1.0);
            transform = CGAffineTransformRotate(transform, M_PI / 2.0);
            break;
            
        case UIImageOrientationRight: //EXIF = 8
            boundHeight = bounds.size.height;
            bounds.size.height = bounds.size.width;
            bounds.size.width = boundHeight;
            transform = CGAffineTransformMakeTranslation(imageSize.height, 0.0);
            transform = CGAffineTransformRotate(transform, M_PI / 2.0);
            break;
            
        default:
            [NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"];
            
    }
    
    UIGraphicsBeginImageContext(bounds.size);
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    if (orient == UIImageOrientationRight || orient == UIImageOrientationLeft) {
        CGContextScaleCTM(context, -scaleRatio, scaleRatio);
        CGContextTranslateCTM(context, -height, 0);
    }
    else {
        CGContextScaleCTM(context, scaleRatio, -scaleRatio);
        CGContextTranslateCTM(context, 0, -height);
    }
    
    CGContextConcatCTM(context, transform);
    
    CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), imgRef);
    UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return imageCopy;
}

///Method in apple documentation.... :)

Wednesday, March 6, 2013

Phone Number Validation in iPhone SDK


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

  int length = [self getLength:textField.text];

  if(length == 10)
  {
    if(range.length == 0)
        return NO;
  }

  if(length == 3)
  {
    NSString *num = [self formatNumber:textField.text];
    textField.text = [NSString stringWithFormat:@"(%@) ",num];
    if(range.length > 0)
        textField.text = [NSString stringWithFormat:@"%@",[num substringToIndex:3]];
  }
  else if(length == 6)
  {
    NSString *num = [self formatNumber:textField.text];
    
    textField.text = [NSString stringWithFormat:@"(%@) %@-",[num  substringToIndex:3],[num substringFromIndex:3]];
    if(range.length > 0)
        textField.text = [NSString stringWithFormat:@"(%@) %@",[num substringToIndex:3],[num substringFromIndex:3]];
  }

  return YES;
}

-(NSString*)formatNumber:(NSString*)mobileNumber
{

mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@"(" withString:@""];
mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@")" withString:@""];
mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@"-" withString:@""];
mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@"+" withString:@""];


int length = [mobileNumber length];
if(length > 10)
{
    mobileNumber = [mobileNumber substringFromIndex: length-10];

}


return mobileNumber;
}


-(int)getLength:(NSString*)mobileNumber
{

  mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@"(" withString:@""];
mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@")" withString:@""];
mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@" " withString:@""];
mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@"-" withString:@""];
mobileNumber = [mobileNumber stringByReplacingOccurrencesOfString:@"+" withString:@""];

int length = [mobileNumber length];

return length;


}

Tuesday, February 26, 2013

how to change Xcode Project name in Xcode 4


For Xcode 4 or later:
  • Open a project
  • Select Project Navigator
  • Highlight project name
  • Single click on project name
    enter image description here

Friday, February 22, 2013

iTellAFriend Feature IOS



What is iTellAFriend?

iTellAFriend is an iOS toolkit for displaying a preconfigued mail composer with a "Tell a Friend" template in ios apps.

Installation

To install iTellAFriend into your app, drag the iTellAFriend.h, .m into your project.
To enable iTellAFriend in your application you need to initialize iTellAFriend before the app has finished launching. The easiest way to do this is to add the iTellAFriend configuration code in your AppDelegate's, like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

  [iTellAFriend sharedInstance].appStoreID = 408981381;

  return YES;
}
To present the iTellAFriend controller, use:
if ([[iTellAFriend sharedInstance] canTellAFriend]) {
  UINavigationController* tellAFriendController = [[iTellAFriend sharedInstance] tellAFriendController];
  [self presentModalViewController:tellAFriendController animated:YES];
}

 
 


Source From :- http://buysourcecode.info/?m=201205

Get Random Number between any two numbers


int RandomNumber = (arc4random()%(toNumber-fromNumber+1))+fromNumber;


Get Random Number from range (Like  50-100)...

Wednesday, January 23, 2013

LocalNotifications in iPhone



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [NSThread detachNewThreadSelector:@selector(fireLocalNotifications) toTarget:self withObject:nil];
 
}

-(void) fireLocalNotifications
{

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    for (int i = 0; i < 60; i++)
    {

        UILocalNotification *localNotification = [[UILocalNotification alloc] init];

        if (localNotification == nil){

            return;
}

        NSDate *notifyDate = [[NSDate date] dateByAddingTimeInterval:i * 60];

        localNotification.fireDate = notifyDate     
     
        localNotification.timeZone = [NSTimeZone defaultTimeZone];

        localNotification.alertBody = [NSString stringWithFormat:NSLocalizedString(@"This is local notification %i"), i];

        localNotification f.alertAction = NSLocalizedString(@"My Details", nil);

        localNotification.soundName = UILocalNotificationDefaultSoundName;

        localNotification.applicationIconBadgeNumber = 1;

        [[UIApplication sharedApplication] scheduleLocalNotification: localNotification];
       
        [localNotification release];

    }

    [pool release];
}

Wednesday, January 16, 2013

moving Image in UIView using UIPanGesture


- (void)viewDidLoad{

    YOURIMAGEVIEW = [[UIImageView alloc]initWithFrame:CGRectMake(130350100100)];
    YOURIMAGEVIEW.image = [UIImage imageNamed:@"image.png"];
    [self.view addSubview: YOURIMAGEVIEW];
    YOURIMAGEVIEW.userInteractionEnabled = YES;
    [self.view bringSubviewToFront: YOURIMAGEVIEW];
  
    panRecognizer = [[UIPanGestureRecognizer allocinitWithTarget:self action:@selector(handlePanFrom:)];
    [panRecognizer setMinimumNumberOfTouches:1];
    [panRecognizer setMaximumNumberOfTouches:1];
    [panRecognizer setDelegate:self];
    [self. YOURIMAGEVIEW addGestureRecognizer:panRecognizer];    

}


- (void)handlePanFrom:(UIPanGestureRecognizer*)recognizer {
    
    CGPoint translation = [recognizer translationInView:recognizer.view];
    CGPoint velocity = [recognizer velocityInView:recognizer.view];
    
    if (recognizer.state == UIGestureRecognizerStateBegan) {
    } else if (recognizer.state == UIGestureRecognizerStateChanged) {
      
    } else if (recognizer.state == UIGestureRecognizerStateEnded) {
       // <animate to final position>
        [UIView animateWithDuration:2.0 delay:0  options:UIViewAnimationOptionCurveEaseOut   animations:^ { self.YOURIMAGEVIEW.center = CGPointMake(velocity.x, velocity.y);} completion:NULL];

    }
}
}