UIProgressView

A UIProgressView looks like horizontal thermometer with blue mercury. You could make it vertical with the CGAffineTransformMakeRotation we saw here, but don’t—everyone expects it 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—everyone expects it to fill from left to right. (What about Arabic and Hebrew?) You could change the color with progressTintColor and trackTintColor, but don’t—everyone expects it to be blue on gray. If the height is less than 10 pixels (or pixel pairs), part of the picture will be cut off. See Progress View in the Human Interface Guidelines.

Source code in Progress.zip

  1. main.m
  2. Class ProgressAppDelegate
  3. Class ViewController calls the setProgress: method of the View every second.
  4. Class View
  5. Icon.png

The timer

This time, the NSTimer is set to repeats: YES. 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 .01 seconds, and add .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. Initialize the label to
    	label.text = @"Downloading 000 of 100";
    
    Update it to
    	label.text = [NSString stringWithFormat: @"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?