iOS – UIActivityIndicatorView example…

 UIActivityIndicatorView is used to show that some long process is processing in background.It can be implemented programatically and using IBOutlet.

In this tutorial we are going to create a UIActivityIndicatorView programatically with start and stop animations.Lets get started,

Step 1: Create a new project in Xcode.

Step 2: Set property for UIActivityIndicatorView in .h file and set @synthesis in .m file.

.h file: 

@property (nonatomic,retain) UIActivityIndicatorView *activityIndicatorObject;

.m file:

@synthesis activityIndicatorObject;

Step 3: Now Initialize UIActivityIndicatorView object and set position.

// Initialize ActivityIndicator object

    activityIndicatorObject = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

// Set Center Position for ActivityIndicator = CGPointMake(150, 150);

   // Add ActivityIndicator to your view

    [self.view addSubview:activityIndicatorObject];

Step 4: Add two buttons in xib and set Action as stopAnimating and startAnimating.These methods are used to start and stop ActivityIndicator.

- (IBAction)startAnimating:(id)sender


[activityIndicatorObject startAnimating]; 


 - (IBAction)stopAnimating:(id)sender


[activityIndicatorObject stopAnimating];


Step 5: Now Run the project.You are Done!!!


iOS – UISwitch example…

UISwitch is an component which resembles the electronic switch with animation.We can change the Switch state by manually or programatically.

In this tutorial we are going to change the state of the UISwitch programatically with suitable changing Label text.Lets have a look at this,

Step 1: Create a new ‘Single view’ project in Xcode.

Step 2: Drag and drop components like UISwitch,UILabel and UIButton.Arrange them as shown below,

Step 3:  Right click over the ‘UISwitch’ component.Now drag and drop in the .h file as shown below.Give a name to your UISwitch and UILabel component which will be referenced later.Set method name for the UISwitch and Button as we did before.

@property (weak, nonatomic) IBOutlet UISwitch *switchObject;

@property (weak, nonatomic) IBOutlet UILabel *switchLabel;

- (IBAction)toggleAction:(id)sender;

- (IBAction)switchAction:(id)sender;

Step 4: Include this method in your .m file.

- (IBAction)toggleAction:(id)sender {



        [switchObject setOn:NO animated:YES];

                       switchLabel.text  = @"Disabled";




 [switchObject setOn:YES animated:YES];

        switchLabel.text  = @"Enabled";



In this method the UISwitch state and label value changes when user pressed the ‘Toggle’ button.

Step 5:Include this method in your .m file.

- (IBAction)switchAction:(id)sender {



       switchLabel.text  = @"Enabled";




        switchLabel.text  = @"Disabled";



In this method the label value changes when user pressed the UISwitch.

Step 6: Now Run the project.You are done…

cocos2d – HelloWorld in Cocos2d…

After the installation, now we gonna have a look at  HelloWorld program.We are not going to implement any code here.When we create a new project in cocos2d, it automatically builds some code in it.

1.Select File–>New–>Project.

2.A window appears as shown below.


3.Select ‘Cocos2d’ and click next.

4.Just run the project.


iOS Simulator Screen shot 18-May-2013 2.06.30 PM

  • Here a Label with text ‘Hello World’ is displayed.
  • The Numbers displayed below are called as ‘FPS'(Frames Per Second).Number of frames displaying per second.

cocos2d – Installing Cocos2d in Xcode…

Yippee:) So Gaming is always a pleasurable thing.Cocos2d has 2 game engines namely,

  1. Box2d
  2. Chipmunk

While comparing to chipmunk,Bx2d is something added with flavour.OK…

Installing Cocos2d:

1. You can Download COCOS2D latest version from” this link

2. open the terminal and type “cd”

3.Drag your latest version of -> COCOS2D package folder in to your terminal window.

4. Type sudo and open the COCOS2D package folder and drag the “” file into your terminal     windows and press enter.

6. put your system password to install templates.

Enjoy gaming!!!

cocos2d – Introduction cocos2d…



It is a framework for building 2D games, demos, and other graphical/interactive applications. It is based on the cocos2d design: it uses the same concepts, but instead of using python it uses objective-c. cocos2d for iPhone is:

  • Easy to use: it uses a familiar API, and comes with lots of examples
  • Fast: it uses the OpenGL ES best practices and optimized data structures
  • Flexible: it is easy to extend, easy to integrate with 3rd party libraries
  • Free: is open source, compatible both with closed and open source games
  • Community supported: cocos2d has an active, big and friendly community (forum, IRC)
  • AppStore approved: More than 2500 AppStore games already use it, including many best seller games.

cocos2d for iPhone supports: iPod TouchiPhoneiPad and OS X


  • Scene management (workflow)
  • Transitions between scenes
  • Sprites and Sprite Sheets
  • Effects: Lens, Ripple, Waves, Liquid, Twirl, etc.
  • Actions (behaviors):
    • Trasformation Actions: Move, Rotate, Scale, Jump, etc.
    • Composable actions: Sequence, Spawn, Repeat, Reverse
    • Ease Actions: Exp, Sin, Cubic, etc.
    • Misc actions: CallFunc, OrbitCamera
  • Basic menus and buttons
  • Integrated physics engine (both Box2d and Chipmunk)
  • Particle system
  • Text rendering support (variable and fixed width fonts)
  • Texture Atlas support
  • Tile Map support (TMXmaps):
    • Orthogonal maps
    • Isometric maps
    • Hexagonal maps
  • Parallax scrolling support
  • Sound support
  • Streak Motion support
  • Render Texture support
  • High Score server (Cocos Live)
  • Point based API: Supports Retina Display
  • Touch/Accelerometer support (iOS).  Keyboard / Mouse support (Mac)
  • Portrait and Landscape mode (iOS) / Automatic Fullscreen support (Mac)
  • Integrated Pause/Resume
  • Fast Textures:Supports PVRTC textures, 8-bit textures, 16-bit textures and 32-bit textures
  • Language: objective-c
  • OpenGL ES 1.1 based (iOS) / OpenGL 1.5 based (Mac)


iOS – UISlider Example…

UISlider is an visual object used to select a single value from a continuous range of values.Values can be selected by sliding.

Step 1: Drag and drop a UITextField and a UISlider in the xib.

Step 2: Set the reference for UISlider and UITextField in the .h file.UISlider as ‘slider’ and UITextField as ‘sliderTextField’.

@property (weak, nonatomic) IBOutlet UISlider *slider;

@property (weak, nonatomic) IBOutlet UITextField *sliderTextField;

Step 3: Set an action method for UISlider as ‘sliderProgress’.

- (IBAction)sliderProgress:(id)sender;

Step 4: Enter this code inside the method ‘sliderProgress’.

 sliderTextField.text = [NSString stringWithFormat:@"%f",slider.value];

Step 5: We are done now,Run the Program !

Java – Java Variable Types

In Java all variables must be declared before the use.basic declaration will be like,


‘ DataType VariableName; ‘


int a;

float b;

Continuous declaration also allowed like ‘int a,b,c;’.

There are three types of variables in java.they are,

  • Local Variable.
  • Instance Variable.
  • Class/Static Variable.

Local Variable:

  • Local variables are declared inside the method,constructor or block.
  • They are visible only inside the block in which they are declared.
  • Local variables do not have a default value so it must be declared  and initialized before the first use.
  • Access modifiers cannot be implemented for local variables.
  • Local variables are destroyed immediately after exits the block.

Example Code:

public class Age {

public void printAge()


int ageCount = 0;        // ageCount is a Local Variable

ageCount = ageCount + 5;

System.out.println(“Age is “+ageCount);


public static void main(String args[])


Age object1 = new Age();




Instance Variable:

  • Instance variables are declared outside the method and constructor or block.
  • Memory will be created in the heap when the instance variable is created.
  • Instance variable is created when an object is created using the ‘new’ keyword.
  • Access modifiers can be applied to these variables.but however ‘private’ is advisable.If the variables needs to be accessed by the subclasses then the visibility can be modified.
  • Instance variables have their default values.So it is not a must to declare and instantiate.Example: int a;
    Here the variable ‘a’ holds 0 as its default value.
  • Instance variables holds values that must be referenced by more than one method,constructor or block.State should be maintained throughout the class.
  • They can be directly called by their name inside the class.Subclasses have to use the qualified name.Example: ‘ObjectName.VariableName’

Example Code:

public class Employee {

public String employeeName;     // employeeName and employeeSalary are Instance Variables

public int employeeSalary;

public Employee(String name)


employeeName = name;


public void setEmployeeValues(int pay)


employeeSalary = pay;

System.out.println(“Employee Name is “+employeeName+” and Employee Salary is “+employeeSalary);


public static void main(String args[])


Employee employee = new Employee(“Manishankar”);




Class/Static Variable:

  • Class variables are also called as Static variables.Variables are declared with a ‘Static’ keyword outside the method,constructor or block.
  • There will be only one copy of the static variable.
  • Static variables can have access modifiers.
  • Static variables starts when the program starts and destroyed when the program stops.
  • Static variables have static memory.
  • Static variables can be accessed by calling the variable with its class name.Example: ‘ClassName.VariableName’

Example Code:

public class Test {

// Salary is a private static variable

private static int salary;

// Name is a constant variable

private static final String name = “Manishankar”;

public static void main(String args[])


salary = 50000;

System.out.println(“Salary is “+salary+” and Name is “+name);