Tag Archives: iPhone

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;

-(void)showWithProgress

{

progress = 0.0f;

progressObject.progress  = progress;

if(progressObject.progress<1)

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

}

-(void)increaseProgress {

progress+=0.1f;

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];

}

OUTPUT:

progressview

PROPERTIES:

progressImage

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.

ProgressTintColor

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.

ProgressViewStyle

The current graphical style of the receiver.

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

TrackImage

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

@property(nonatomic, retain) UIImage *trackImage

TrackTintColor

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.
Advertisements

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

    activityIndicatorObject.center = 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 {

    if(switchObject.on)

    {

        [switchObject setOn:NO animated:YES];

                       switchLabel.text  = @"Disabled";

    }

    else

    {

 [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 {

    if(switchObject.on)

    {

       switchLabel.text  = @"Enabled";

    }

    else

    {

        switchLabel.text  = @"Disabled";

        }

}

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

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