In this application we are going to create slider by using Window based application. There is .h and .m file. We are going to add Slider to Window.
In this application we are going to create slider by using Window based application. There is .h and .m file. We are going to add Slider to Window.In this application we are going to create slider by using Window based application. There is .h and .m file. We are going to add Slider to Window.
Create a new project by selecting Window-Based Application.Open the Interface Builder by double clicking the MainWindow.xib file and add a Slider and label from the library. label is used to display the value of slider.
here we are declaring Slider as mslider(its a variable) using UISlider. It looks like this
IBOutlet UISlider *mswitch;
IBOutlet UILabel *labelTxt;
and property is defined for labelTxt
@property (nonatomic, retain) UILabel *labelTxt;
we are writing the action on button i.e.
-(IBAction)changeSlider:(id)sender ;
To set slider max. and min value sellect slider and then tools and inspector
SliderAppDelegate.h file will look like this:
#import <UIKit/UIKit.h> @interface SliderAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; IBOutlet UISlider *slider; IBOutlet UILabel *labelTxt; } @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) UILabel *labelTxt; -(IBAction)changeSlider:(id)sender ; @end
SliderAppDelegate.m
#import "SliderAppDelegate.h" @implementation SliderAppDelegate @synthesize window,labelTxt ; - (void)applicationDidFinishLaunching:(UIApplication *)application { [window makeKeyAndVisible]; } -(IBAction)changeSlider:(id)sender { labelTxt .text= [[NSString alloc] initWithFormat:@" Value %d ", (int)slider.value]; } - (void)dealloc { [window release]; [label.Txt release]; [super dealloc]; } @end
SliderAppDelegate.m file will look like this:
after all the applications connect all outlets and action.
In this we are writing the method for slider
Final expression will look like this: