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(45209721);
    [UIView beginAnimations:@"First" context:NULL];
    [UIView setAnimationBeginsFromCurrentState:YES];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDuration:6.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    labltext.frame=CGRectMake(1813219721);
    [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 FrameworkQuartzCore.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(00myScrollView.contentSize.width,
                                                                                                      myScrollView.contentSize.height);

                                   [myScrollView.layer renderInContextUIGraphicsGetCurrentContext()];
                                   screenshot = UIGraphicsGetImageFromCurrentImageContext();
                                   myScrollView.contentOffset = savedContentOffset;
                                   myScrollView.frame = savedFrame;
                       }
                       UIGraphicsEndImageContext();
           //Save Image to Local Library     UIImageWriteToSavedPhotosAlbum(imageself@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.

Monday 4 February 2013

Create A Project in TabbarController in Xcode



Step1: File --> New --> Project --> Application --> Empty Application --> Project Name --> Create.

Step2: Automatically Created Files are


Step3: And Create a New File for MainWindow.Xib (UserInterface --> Window).

Step4: Create Object And Class Name is Changed into AppDelegate.

Step5: Create the New TabbarController


Step6: Change the AppDelegate Codings are

     AppDelegate.h

             @property (strong, nonatomic) IBOutlet UIWindow *window;
            @property (strong, nonatomic) IBOutlet UITabBarController *tabbar;
            //*important --- IBOutlet

    AppDelegate.m

           @synthesize window,tabbar;

            - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
           {
                   [self.window addSubview:tabbar.view];
                   self.window.backgroundColor = [UIColor whiteColor];
                   [self.window makeKeyAndVisible];
                   return YES;
          }

Step7: Connect the Outlets are

  • MainWindow.Xib --> FileOwner --> ClassName Changed to UIApplication.
  • MainWindow.Xib --> FileOwner --> Connect Outlet --> delegate into AppDelegate.
  • MainWindow.Xib --> AppDelegate(Object) --> Connect Outlet --> Tabbar into TabbarController, window into Window.
  • Project Header --> Summary --> MainInterface --> Select MainWindow.
Step10: Tabbar Item1 Select --> Change Class into ViewController1(Example).

Step11: Tabbar Item1 Select --> Change Class into ViewController2(Example).

Step12: Add a Navigation Controller in TabbarController.

  • Navigation Controller name is Item
  • The Class is Changed into ViewController3(Example)







OutPut:

Item1                                                                    Item2

              


Item3(With Navigation Controller)