Tag Archives: ios

iOS – UIStepper Example…

UIStepper was introduced in iOS 5.0.It provides an option for the user to increment or decrement values.Now we are going to create a project with UIStepper which displays increment or decrement values.

  • open Xcode and Select Create a new Xcode project –>Single View Application.
  • Enter the product name as ‘UIStepperExample‘,this will remain as your project name.
  • Enter company identifier,organizaton name,bundle identifier.
  • Check option Use Automatic Reference Counting and uncheck option Use Storyboards.


  • Drag and drop the UIStepper and UILabel in the .xib file like,


  • ctrl + drag from UIStepper to interface section to create an outlet for UIStepper and name it as ‘stepperOutlet‘.


  • ctrl+drag from UILabel to interface section to create an outlet for UILabel and name it as ‘stepperLabel‘.


  • ctrl+drag from UIStepper to interface section to create an Action for UIStepper and name it as ‘stepperClicked‘.


  • Now add this code to ViewController.m file inside the ‘viewDidLoad‘ method.

self.stepperOutlet.minimumValue = 0;

self.stepperOutlet.maximumValue = 1000;

self.stepperOutlet.stepValue = 10;

self.stepperOutlet.autorepeat = YES;

self.stepperOutlet.continuous = YES;

self.stepperLabel.text = [NSString stringWithFormat:@"Value:%d",0];

What’s this,

Minimum Value:It is the minimum value the UIStepper will start from.Here we our minimum value is ‘0‘.

Maximum Value:It is the maximum value of the UIStepper can reach.Here our maximum value is ‘1000‘.

Step Value:It is the value by which UIStepper will increment or decrement each time when we press ‘+‘ or ‘‘ button.

Autorepeat:If ‘YES’ the UIStepper will continuously increment or decrement the value when the ‘+‘ or ‘‘ button is press and hold.

Continuous:If ‘YES’ the value change events are send immediately when the user clicks ‘+‘ or ‘‘ button.If ‘NO’ the value changing events are send when the user interaction ends.


  • Now add this code inside the method ‘stepperClicked‘,

int stepperIntValue = self.stepperOutlet.value;
self.stepperLabel.text = [NSString stringWithFormat:@"Value:%d",stepperIntValue];



iOS – UIPageControl example…

A Pagecontrol presents user with a set of horizontal dots representing pages.The current page is presented as white dot.We can navigate to the next or previous pages.In this example we will create a page control with displaying page number. 

  • Create a new project as, Create a new Xcode project –>Single View Application
  • Enter the Product name as PageControlExample.This will be your project name.
  • Enter Organization name,company identifier,bundle identifier and check use Automatic Reference counting.Uncheck the use Storyboard option.
  • Drag and drop the UIPageControl in the .xib file.It looks like,

  • ctrl+drag from pagecontrol to interface section to create an outlet.


  • Drag and drop a label in the .xib file and create an outlet like we did before.
  •   create an action for the pagecontrol and name it as changePage,

Now add this lines inside the changePage method ,

self.pageNumber.text = [NSString stringWithFormat:@"%i", ([self.pageControl currentPage]+1)];

Congratulation !  Finally…

iOS – UIProgressView Example…

ProgressView is used to show progress of work.For example downloading,retrieving values from web service.

Create the UIProgressView by setting referencing outlets with getter and setter property.

@property (strong, nonatomic) IBOutlet UIProgressView *progressObject;

@synthesize progressObject;

Create a button with method named,

- (IBAction)startProgress:(id)sender;

Implement the methods in the .m file,

static float progress = 0.0f;



progress = 0.0f;

progressObject.progress  = progress;


[self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.3];


-(void)increaseProgress {


progressObject.progress = progress;

if(progress < 1.0f)

[self performSelector:@selector(increaseProgress) withObject:nil afterDelay:0.3];


Now just call these methods like this,

- (IBAction)startProgress:(id)sender


[self showWithProgress];






An image to use for the portion of the progress bar that is filled.

@property(nonatomic, retain) UIImage *progressImage
  • Available in iOS 5.0 and later.


The color shown for the portion of the progress bar that is filled.

@property(nonatomic, retain) UIColor *progressTintColor
  • Available in iOS 5.0 and later.


The current graphical style of the receiver.

@property(nonatomic) UIProgressViewStyle progressViewStyle
  • Available in iOS 2.0 and later.


An image to use for the portion of the track that is not filled.

@property(nonatomic, retain) UIImage *trackImage


The color shown for the portion of the progress bar that is not filled.

@property(nonatomic, retain) UIColor *trackTintColor
  • Available in iOS 5.0 and later.

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 – 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
http://www.cocos2d-iphone.org/download” 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 “install-templates.sh” file into your terminal     windows and press enter.

6. put your system password to install templates.

Enjoy gaming!!!

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 !