3

I have a UIToolbar in which I have placed a UIProgressView successfully. However, I have seen some apps contain a small label above the UIProgressView which tells the user what the program is doing where progress is being made -- e.g. to download a file. However it seems that this cannot be done in UI Builder. Any ideas on the best way to add the label ablve the UIProgressView in the toolbar? Here is what I am interested in:

+------------------------------------------------+
|         Uploading File                         |
| ================--------------------  [CANCEL] |
+------------------------------------------------+
Jason
  • 14,517
  • 25
  • 92
  • 153

3 Answers3

3

Make a custom UIView that contains a UILabel and UIProgressView as subviews. You then insert the custom UIView into the toolbar.

Alex Reynolds
  • 95,983
  • 54
  • 240
  • 345
2

You can actually also add text directly to a UIProgressView as a subview, ex:

UIProgressView *videoProgressView = [[UIProgressView alloc] initWithFrame:CGRectMake(40, self.view.frame.size.height/2, self.view.frame.size.width - 80, 40)];

UILabel *processing = [[UILabel alloc] initWithFrame:CGRectMake(0, -50, videoProgressView.frame.size.width, 25)];
processing.text = @"Processing Video...";
processing.textAlignment = NSTextAlignmentCenter;

[videoProgressView addSubview:processing];

[self.view addSubview:videoProgressView];

Just make sure UIProgressView's clipsToBounds property is set to NO.

Lyndsey Scott
  • 37,080
  • 10
  • 92
  • 128
0

Here's a Swift 5 implementation of Lyndsey Scott's answer used in my project:

let view = UIApplication.topViewController()!.view!

let progressView = UIProgressView(progressViewStyle: .default)
progressView.center = view.center
progressView.trackTintColor = .gray
progressView.frame = CGRect(x: 40, y: view.frame.size.height / 2, width: view.frame.size.width - 80, height: 40)
      
let progressViewLabel = UILabel(frame: CGRect(x: 0, y: -50, width: progressView.frame.size.width, height: 25))
progressViewLabel.text = "Migrating database:"
progressViewLabel.textAlignment = .center
      
progressView.addSubview(progressViewLabel)
      
view.addSubview(progressView)
lukemmtt
  • 476
  • 6
  • 15