如何在 UIToolbar 中的 UIProgressView 上方添加标签?
我有一个 UIToolbar,其中已成功放置 UIProgressView。然而,我看到一些应用程序在 UIProgressView 上方包含一个小标签,它告诉用户程序正在做什么以及正在取得进展 - 例如下载文件。然而,这似乎无法在 UI Builder 中完成。关于在工具栏中添加 UIProgressView 标签的最佳方法有什么想法吗?这是我感兴趣的:
+------------------------------------------------+
| Uploading File |
| ================-------------------- [CANCEL] |
+------------------------------------------------+
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] |
+------------------------------------------------+
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建一个自定义
UIView
,其中包含UILabel
和UIProgressView
作为子视图。然后将自定义UIView
插入工具栏中。Make a custom
UIView
that contains aUILabel
andUIProgressView
as subviews. You then insert the customUIView
into the toolbar.实际上,您还可以将文本作为子视图直接添加到
UIProgressView
中,例如:只需确保
UIProgressView
的clipsToBounds
属性设置为 NO。You can actually also add text directly to a
UIProgressView
as a subview, ex:Just make sure
UIProgressView
'sclipsToBounds
property is set to NO.以下是我的项目中使用的 Lyndsey Scott 的答案 的 Swift 5 实现:
Here's a Swift 5 implementation of Lyndsey Scott's answer used in my project: