SliderExample Application in iPhone

In this application we will see how to Slider worked and change the value in iPhone. So let see how it will worked.

Step 1: Open the Xcode, Create a new project using View Base application. Give the application “SliderExample”.

Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.

Step 3: Expand classes and notice Interface Builder created the ViewController class for you. Expand Resources and notice the template generated a separate nib, SliderExampleViewController.xib for the EmailSend application.

Step 4: Open the SliderExampleViewController.h file and make the following changes:

#import <UIKit/UIKit.h>
@interface SliderExampleViewController : UIViewController {
IBOutlet UISlider *sliderValue;
IBOutlet UILabel *sliderValueTxt;
}
@property (nonatomic, retain) UILabel *sliderValueTxt;
(IBAction)SliderValue:(id)sender;

Step 6: Double click the SliderExampleViewController.xib file and open it to the interface Builder. Drag the slide and label from the library and place it to the View window. Now select the slide and bring up Connection Inspector and connect
ValueChange to the File’s Owner icon and select SliderValue: method and connect File’s owner icon to label and select sliderValueTxt Now Save the .xib file, close it and go back to the Xcode.

Step 7: Open the SliderExampleViewController.m file and make the following changes:

#import "SliderExampleViewController.h"
@implementation SliderExampleViewController
@synthesize sliderValueTxt;
(void)dealloc
{
[super dealloc];
}
(IBAction)SliderValue:(id)sender
{
sliderValueTxt .text= [[NSString alloc] initWithFormat:@"%d ", (int)sliderValue.value];
}
(void)didReceiveMemoryWarning
{
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren’t in use.
}
#pragma mark – View lifecycle
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
– (void)viewDidLoad
{
[super viewDidLoad];
}
*/

(void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end

Step 8: Now Compile and run the application on the Simulator.

Leave a Reply

Your email address will not be published. Required fields are marked *