Monday, 25 March 2013

Add Done Button on Numeric Keyboard in Xcode

Here is following code you have to use to add a Done button on Numeric Keyboard

In .h file you have to add a new Button named Done

  UIButton *doneButton;


After this you have to implement following code in .m file


- (void)addButtonToKeyboard {
    // create custom button
    if (doneButton == nil) {
        doneButton  = [[UIButton alloc] initWithFrame:CGRectMake(0, 163, 106, 53)];
    }
    else {
        [doneButton setHidden:NO];
    }

    [doneButton addTarget:self action:@selector(doneButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    // locate keyboard view
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
    UIView* keyboard = nil;
    for(int i=0; i<[tempWindow.subviews count]; i++) {
        keyboard = [tempWindow.subviews objectAtIndex:i];
        // keyboard found, add the button
        if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2) {
            if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
                [keyboard addSubview:doneButton];
        } else {
            if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
                [keyboard addSubview:doneButton];
        }
    }
}
- (void)doneButtonClicked:(id)Sender {
   // Here we'll write our code to for button action
}

Thursday, 21 March 2013

iOS - Rate the App in AppStore


Unzip the iRate-master.zip --> Click the iRate-master folder  --> Click the iRate Folder --> Select the all files into your project.
In iRate Folder has Files are

        1. iRate.bundle
        2. iRate.h
        3. iRate.m

Step 1:
Create a new project --> Name as rate me & tick the use automatic reference counting 


                                                   (or)

Existing Project --> select the Project --> click the target(Project Name) --> Selct the buildPhases --> Compiled Sources --> double click the iRate.m --> Type the -fobjc-arc




Step 2:
AppDelegate.m

#import "iRate.h"

+ (void)initialize
{
    //configure iRate
    [iRate sharedInstance].applicationBundleID = @"com.company.appname";// Replace this
    [iRate sharedInstance].usesUntilPrompt = 4;
    [iRate sharedInstance].previewMode = YES;
}


Button Coding to Rate your App:
-(IBAction)action_rate:(id)sender
{
    [[iRate sharedInstance] openRatingsPageInAppStore];
}

Friday, 15 February 2013

Animate Label or Image in Xcode

.h File

#import <UIKit/UIKit.h>

@interface Animation : UIViewController
{
    IBOutlet UILabel *labltext;
}

@property(nonatomic,retain)IBOutlet UILabel *labltext;

@end


.m File

-(void)viewDidLoad
{
    labltext.frame=CGRectMake(45, 20, 97, 21);
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:6.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    labltext.frame=CGRectMake(181, 321, 97, 21);
    [UIView commitAnimations];
}


Spin A label

-(void)viewDidLoad
{
    labltext.frame=CGRectMake(45, 20, 97, 21);
    [UIView beginAnimations:@"First" context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:6.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    labltext.frame=CGRectMake(181, 321, 97, 21);
    [UIView commitAnimations];
}


- (void)animationDidStop:(NSString *)animID finished:(BOOL)didFinish context:(void *)context
{
    if ([animID isEqualToString:@"First"])
    {
        [UIView beginAnimations:@"Last" context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:2.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        labltext.frame=CGRectMake(10, 375, 100, 30);
        [UIView commitAnimations];
        
    }
    else if ([animID isEqualToString:@"Last"])
    {
        [UIView beginAnimations:@"Last1" context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:2.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        labltext.frame=CGRectMake(220, 20, 100, 30);
        [UIView commitAnimations];
        
    }
    
    else if ([animID isEqualToString:@"Last1"])
    {
        [UIView beginAnimations:@"First1" context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:2.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        labltext.frame=CGRectMake(10, 10, 100, 30);
        [UIView commitAnimations];
        
    }
    else if ([animID isEqualToString:@"First1"])
    {
        [UIView beginAnimations:@"First" context:NULL];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDuration:2.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        labltext.frame=CGRectMake(220, 200, 100, 30);
        [UIView commitAnimations];
        
    }

}

Tuesday, 12 February 2013

Implement a .rtf or .doc file Show in WebView (Xcode)

Add the which Any Format File (doc,rtf,.....etc) you want shown in WebView.


.h File:


@interface LocalFileWebView : UIViewController
{
    IBOutlet UIWebView *Webviewlocal;
}

@property(nonatomic,retain) IBOutlet NSString *Name;

@end



.m File:

@synthesize Name;

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title=@"TamilNadu Details";
    
    self.Name=@"Tamilnadu";
    
    NSString *path=[[NSBundle mainBundle] pathForResource:self.Name ofType:@"rtf"];
    NSURL *url=[NSURL fileURLWithPath:path];
    NSURLRequest *req=[NSURLRequest requestWithURL:url];
    [Webviewlocal loadRequest:req];
}


Output:


         Map the WebView and Run the Application.






Implement Coding for Screen Shot for View in Xcode

             Add the Framework : QuartzCore.framework
           
              .h File:

              #import <QuartzCore/QuartzCore.h>

              
             .m File (Button for CaptureImage):
             //Coding for Screen Shot for View(saved to Photo Library in Your Device)

                       UIGraphicsBeginImageContext(self.view.frame.size);
                       [[self.view layer] renderInContext:UIGraphicsGetCurrentContext()];
                       UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
                       UIGraphicsEndImageContext();
                      //Save Image to Local Library
                      UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
       

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIAlertView *alert;
    if (error)
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                           message:@"Unable to save image to Photo Album."
                                          delegate:self cancelButtonTitle:@"Ok"
                                 otherButtonTitles:nil];
    }
    else
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Success"
                                           message:@"Image saved to Photo Album."
                                          delegate:self cancelButtonTitle:@"Ok"
                                 otherButtonTitles:nil];
    }
    [alert show];

}


              Add the Framework : QuartzCore.framework
           
              .h File:

              #import <QuartzCore/QuartzCore.h>          


             .m File (Button for CaptureImage):
             //Coding for Screen Shot for ScrollView (saved to Photo Library in Your Device)

                       UIImage * screenshot;
                       UIGraphicsBeginImageContext(myScrollView.contentSize);
                       {
                                   CGPoint savedContentOffset = myScrollView.contentOffset;
                                   CGRect savedFrame = myScrollView.frame;
                                   myScrollView.contentOffset = CGPointZero;
                                   myScrollView.frame = CGRectMake(0, 0, myScrollView.contentSize.width,
                                                                                                      myScrollView.contentSize.height);

                                   [myScrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
                                   screenshot = UIGraphicsGetImageFromCurrentImageContext();
                                   myScrollView.contentOffset = savedContentOffset;
                                   myScrollView.frame = savedFrame;
                       }
                       UIGraphicsEndImageContext();
           //Save Image to Local Library     UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);                     
       

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIAlertView *alert;
    if (error)
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                           message:@"Unable to save image to Photo Album."
                                          delegate:self cancelButtonTitle:@"Ok"
                                 otherButtonTitles:nil];
    }
    else
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Success"
                                           message:@"Image saved to Photo Album."
                                          delegate:self cancelButtonTitle:@"Ok"
                                 otherButtonTitles:nil];
    }
    [alert show];

}


Implementing Touch and Moved the Objects in Xcode

TouchingFunctionality.h File

#import <UIKit/UIKit.h>

@interface TouchingFunctionality : UIViewController
{
    IBOutlet UIImageView *image1;
    IBOutlet UIImageView *image2;
    IBOutlet UIImageView *image3;
    IBOutlet UIImageView *image4;
    IBOutlet UIImageView *image5;
    IBOutlet UIImageView *image6;
    IBOutlet UIImageView *image7;
    IBOutlet UIImageView *image8;
}

@end


TouchingFunctionality.m File


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title=@"Touch Function";
    
    
    UIBarButtonItem *btnSave=[[UIBarButtonItem alloc]initWithTitle:@"Save" style:UIBarButtonItemStyleBordered target:self action:@selector(save_Clicked)];
    self.navigationItem.rightBarButtonItem = btnSave;
    [btnSave release];
   
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    // get touch event
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
  if ([touch view] == image1) 
  {        
     image1.center = touchLocation;
  }
  else if ([touch view] == image2) 
  {        
     image2.center = touchLocation;
  }
  else if ([touch view] == image3) 
  {
     image3.center = touchLocation;
  }
  else if ([touch view] == image4) 
  {
     image4.center = touchLocation;
  }
  else if ([touch view] == image5) 
  {        
     image5.center = touchLocation;
  }
  else if ([touch view] == image6) 
  {       
     image6.center = touchLocation;
  }
  else if ([touch view] == image7) 
  {
     image7.center = touchLocation;
  }
  else if ([touch view] == image8) 
  {
     image8.center = touchLocation;
  }
}

//Saved a View as Image

-(void)save_Clicked
{
    UIGraphicsBeginImageContext(self.view.frame.size);
    [[self.view layer] renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    UIImageWriteToSavedPhotosAlbum(screenshot, nil, nil, nil);
}





Output:


View --> Attributes Inspector --> Change the propery of Interaction

                                                        * Enable the tick for Multiple Touch and User Interaction Enabled.




     * Map the images and Run the Application



Monday, 11 February 2013

MemoryLeak Test in Xcode

Steps:

  1. Connect device and Select device option  in debug mode

  2.Run application as below mentioned

  3.Application Run on device and below Instruments window show in system. 

  4.Test application in the device.Every 10 seconds Instruments window check leaks in device.If application have any leaks that show in leaks bar continuous blue bar line and show which object leaked in below Leaked block.

  5.Know more about leaks click extended view in view bar as below mentioned small black dotted box.Extended detail box display at right of window and show leaks as mentioned black box.Double click 7. (or) 8. in extended detail view that show the program and display which line leaks appeared in purple color line and also display how many percentage of memory leaked.


Note : Before Check the MemoryLeak Test for Submitting Apps in AppStore.