HomeMenu
Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

UIProgressView

UIProgressView displays the progress of a task over time.

Example

UIProgressView

Instructions

Create

  1. Open Xcode
  2. Click File
  3. Click New
  4. Click Project...
  5. Under iOS, click Application
  6. Click Single View Application
  7. Click Next
  8. After Product Name, type your product name
  9. After Organization Name, type your organization name or leave blank
  10. After Organization Identifier, type your organization identifier
  11. After Language, select Swift
  12. After Devices, select Universal
  13. Uncheck Use Core Data
  14. Click Next
  15. Select a folder
  16. After Source Control, uncheck Create Git repository on
  17. Click Create

Edit ViewController.swift

  1. Open ViewController.swift
  2. Copy and paste code

Edit Main.storyboard

  1. Open Main.storyboard
  2. Click View
  3. Click Utilities
  4. Click Show Object Library
  5. Drag Progress View to View
  6. Click View
  7. Click Utilities
  8. Click Show Connections Inspector
  9. Under Referencing Outlets, after New Referencing Outlet, drag + to View Controller
  10. Click interfaceBuilderProgressView

Add Image

  1. Click File
  2. Click Add Files to "UIProgressView" ...
  3. Select image
  4. After Destination, check Copy items if needed
  5. After Added folders, select Create groups
  6. After Add to targets, check UIProgressView
  7. Click Add

Run

  1. Click Product
  2. Click Run

Code

import UIKit

class ViewController: UIViewController
{
    @IBOutlet weak var interfaceBuilderProgressView: UIProgressView!
    
    override func prefersStatusBarHidden() -> Bool
    {
        return true
    }
    override func viewDidLoad()
    {
        super.viewDidLoad()
        
        self.view.removeConstraints(self.view.constraints())
        self.view.addConstraint(NSLayoutConstraint(item: self.interfaceBuilderProgressView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Height, multiplier: 0, constant: 30))
        self.view.addConstraint(NSLayoutConstraint(item: self.interfaceBuilderProgressView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: 0))
        
        let button = UIButton.buttonWithType(UIButtonType.System) as UIButton
        button.addTarget(self, action: "touchUpInside:", forControlEvents: UIControlEvents.TouchUpInside)
        button.setTitle("Animate", forState: UIControlState.Normal)
        button.setTranslatesAutoresizingMaskIntoConstraints(false)
        self.view.addSubview(button)
        self.view.addConstraint(NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: self.interfaceBuilderProgressView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        self.view.addConstraint(NSLayoutConstraint(item: button, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: 0))
        
        let progressProgressView = UIProgressView()
        progressProgressView.progress = 0.5
        progressProgressView.setTranslatesAutoresizingMaskIntoConstraints(false)
        self.view.addSubview(progressProgressView)
        self.view.addConstraint(NSLayoutConstraint(item: progressProgressView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: button, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        self.view.addConstraint(NSLayoutConstraint(item: progressProgressView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Height, multiplier: 0, constant: 30))
        self.view.addConstraint(NSLayoutConstraint(item: progressProgressView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: 0))

        let progressViewStyleProgressView = UIProgressView()
        progressViewStyleProgressView.progress = 0.5
        progressViewStyleProgressView.progressViewStyle = UIProgressViewStyle.Bar
        progressViewStyleProgressView.setTranslatesAutoresizingMaskIntoConstraints(false)
        self.view.addSubview(progressViewStyleProgressView)
        self.view.addConstraint(NSLayoutConstraint(item: progressViewStyleProgressView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: progressProgressView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        self.view.addConstraint(NSLayoutConstraint(item: progressViewStyleProgressView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Height, multiplier: 0, constant: 30))
        self.view.addConstraint(NSLayoutConstraint(item: progressViewStyleProgressView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: 0))

        let progressTintColorProgressView = UIProgressView()
        progressTintColorProgressView.progress = 0.5
        progressTintColorProgressView.progressTintColor = UIColor.redColor()
        progressTintColorProgressView.setTranslatesAutoresizingMaskIntoConstraints(false)
        self.view.addSubview(progressTintColorProgressView)
        self.view.addConstraint(NSLayoutConstraint(item: progressTintColorProgressView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: progressViewStyleProgressView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        self.view.addConstraint(NSLayoutConstraint(item: progressTintColorProgressView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Height, multiplier: 0, constant: 30))
        self.view.addConstraint(NSLayoutConstraint(item: progressTintColorProgressView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: 0))

        let trackTintColorProgressView = UIProgressView()
        trackTintColorProgressView.progress = 0.5
        trackTintColorProgressView.trackTintColor = UIColor.redColor()
        trackTintColorProgressView.setTranslatesAutoresizingMaskIntoConstraints(false)
        self.view.addSubview(trackTintColorProgressView)
        self.view.addConstraint(NSLayoutConstraint(item: trackTintColorProgressView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: progressTintColorProgressView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        self.view.addConstraint(NSLayoutConstraint(item: trackTintColorProgressView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Height, multiplier: 0, constant: 30))
        self.view.addConstraint(NSLayoutConstraint(item: trackTintColorProgressView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: 0))

        let progressImageProgressView = UIProgressView()
        progressImageProgressView.progress = 0.5
        progressImageProgressView.progressImage = UIImage(named: "HappyFace") // not working properly as of iOS8
        progressImageProgressView.setTranslatesAutoresizingMaskIntoConstraints(false)
        self.view.addSubview(progressImageProgressView)
        self.view.addConstraint(NSLayoutConstraint(item: progressImageProgressView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: trackTintColorProgressView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        self.view.addConstraint(NSLayoutConstraint(item: progressImageProgressView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Height, multiplier: 0, constant: 30))
        self.view.addConstraint(NSLayoutConstraint(item: progressImageProgressView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: 0))

        let trackImageProgressView = UIProgressView()
        trackImageProgressView.progress = 0.5
        trackImageProgressView.setTranslatesAutoresizingMaskIntoConstraints(false)
        trackImageProgressView.trackImage = UIImage(named: "HappyFace") // not working properly as of iOS8
        self.view.addSubview(trackImageProgressView)
        self.view.addConstraint(NSLayoutConstraint(item: trackImageProgressView, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: progressImageProgressView, attribute: NSLayoutAttribute.Bottom, multiplier: 1, constant: 0))
        self.view.addConstraint(NSLayoutConstraint(item: trackImageProgressView, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Height, multiplier: 0, constant: 30))
        self.view.addConstraint(NSLayoutConstraint(item: trackImageProgressView, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: 0))
    }
    func touchUpInside(sender: UIButton!)
    {
        self.interfaceBuilderProgressView.setProgress(1, animated: true)
    }
}

Apple UIKit