3

我有一个 UIToolbar 我已经成功放置了一个 UIProgressView 。但是,我看到一些应用程序在 UIProgressView 上方包含一个小标签,它告诉用户程序在哪里取得了进展——例如下载文件。然而,这似乎不能在 UI Builder 中完成。关于在工具栏中添加标签的最佳方法有什么想法吗?这是我感兴趣的:

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

3 回答 3

3

制作一个UIView包含UILabelUIProgressView作为子视图的自定义。然后将自定义UIView插入工具栏中。

于 2010-08-02T06:25:15.770 回答
2

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

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' 的clipsToBounds属性设置为 NO。

于 2015-01-27T22:55:20.557 回答
0

这是我的项目中使用的Lyndsey Scott 答案的 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)
于 2021-05-31T13:31:20.187 回答