UIProgressView

The progress view looked more three-dimensional in iOS 6:

Source code in Progress.zip

  1. Class AppDelegate: unchanged.
  2. Class ViewController calls the setProgress method of the View every second until the progress view is full.
  3. Class View

The progress view

A UIProgressView looks like horizontal thermometer with blue mercury. You could make it vertical with the CGAffineTransformMakeRotation we saw here, but don’t do it—everyone expects the progress view to be horizontal. It fills from left (0.0) to right (1.0). You could fill it from right to left by giving a horizontal scale of –1 to CGAffineTransformMakeScale, but don’t do it—everyone expects the progress view to fill from left to right. (What about Arabic and Hebrew?) You could change the color with progressTintColor and trackTintColor, but don’t do it—everyone expects the progress view to be blue on gray. Don’t specify a height for the UIProgressView; it defaults to 2 pairs of pixels on iPhone 6.

Two ways to set the level of mercury:

  1. Assign to the progress property of the progress view.
  2. Call the setProgress(_:animated:) method of the progress view.

See Progress View in the Human Interface Guidelines.

The timer

Unlike the NSTimer in the Activity app, the timer in this app is set to repeats: true. The infinite loop is broken when the setProgress method of class View invalidates the timer.

Things to try

  1. Make the progress indicator run more smoothly. Reduce the interval to 0.01 seconds (with a leading zero), and add 0.001 to the progress each time we update it.

  2. Display integers from 0 to 100 instead of fractions from 0.0 to 1.0. Change the label to a monospace font and initialize its text as follows.
    		label.font = UIFont(name: "Courier", size: UIFont.labelFontSize());
    		//three spaces before the first zero
    		label.text = "Downloading   0 of 100";
    
    Update it to
    		label.text = String(format: "Downloading %3d of %3d", Int(100 * progressView.progress), 100);
    

  3. Could we use an NSTimer in Switch to update a time display while the music is playing?