Sunday, September 21, 2014

UIActivity IndicatorView using swift iPhone

In this article create UIActivity IndicatorView in iPhone using swift programming langauge.


To create UIActivity indicator in iPhone using swift.
Create object of UIActivityIndicator

 let indicator:UIActivityIndicatorView = UIActivityIndicatorView (activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)

Set property to activity indicator like


Color
        indicator.color = UIColor .magentaColor() 
Frame :
indicator.frame = CGRectMake(0.0, 0.0, 10.0, 10.0) 
Position
indicator.center = self.view.center

After this add this subview to main  view

self.view.addSubview(indicator)

Now to display this indicator on the view 

indicator.bringSubviewToFront(self.view)

There are methods for show and hide this view is

  1. startAnimating()
  2. stopAnimating()
To use this methods when you want to show the indicator call this indicator.startAnimating()

and when you want to hide this indicator call this indicator.stopAnimating()

The full code for UIActivity IndicatorView 

let indicator:UIActivityIndicatorView = UIActivityIndicatorView (activityIndicatorStyle: UIActivityIndicatorViewStyle.Gray)
        indicator.color = UIColor .magentaColor()
        indicator.frame = CGRectMake(0.0, 0.0, 10.0, 10.0)
        indicator.center = self.view.center
        self.view.addSubview(indicator)
        indicator.bringSubviewToFront(self.view)
        indicator.startAnimating()

Output :



Hope this article is helpful for you...





 

No comments:

Post a Comment