如何在UIToolbar中的UIProgressView上面添加标签?

时间:2010-08-02 04:54:59

标签: iphone uitoolbar uiprogressview

我有一个UIToolbar,我已成功放置了UIProgressView。但是,我看到一些应用程序在UIProgressView上方包含一个小标签,它告诉用户程序正在进行哪些进程 - 例如下载文件。但是,似乎无法在UI Builder中完成此操作。有关添加标签的最佳方法的任何想法都取消了工具栏中的UIProgressView吗?以下是我感兴趣的内容:

+------------------------------------------------+
|         Uploading File                         |
| ================--------------------  [CANCEL] |
+------------------------------------------------+

3 个答案:

答案 0 :(得分:4)

制作包含UIViewUILabel作为子视图的自定义UIProgressView。然后,将自定义UIView插入工具栏。

答案 1 :(得分:0)

您实际上也可以将文本作为子视图直接添加到UIProgressView,例如:

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];

只需确保UIProgressView的{​​{1}}属性设置为NO。

答案 2 :(得分:0)

这是我的项目中使用的 Lyndsey Scott's answer 的 Swift 5 实现:

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)