添加UIActivityIndi​​catorView到UIBarButton [英] Add UIActivityIndicatorView into UIBarButton

查看:150
本文介绍了添加UIActivityIndi​​catorView到UIBarButton的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何添加一个UIActivityIndi​​catorView微调圈成UIBarButton,这样当用户点击导航栏上的按钮之一,他们看到一个微调,同时加载发生?

How do I add a UIActivityIndicatorView spinner circle into a UIBarButton, so that when a user taps on one of those buttons on the navigation bar, they see a spinner while the loading takes place?

推荐答案

如果你想显示的导航栏按钮活动轮(例如,你可能对你的导航栏刷新按钮) - 您可以创建一个新的的UIBarButtonItem 与自定义视图作为 UIActivityIndi​​catorView

If you're trying to show the activity wheel in a navigation bar button (e.g. you might have a refresh button on your navbar) - you can create a new UIBarButtonItem with a custom view being the UIActivityIndicatorView:

的Objective-C

uiBusy = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
uiBusy.hidesWhenStopped = YES;
[uiBusy startAnimating];
[self.navigationItem.rightBarButtonItem initWithCustomView:uiBusy];

斯威夫特

let uiBusy = UIActivityIndicatorView(activityIndicatorStyle: .White)
uiBusy.hidesWhenStopped = true
uiBusy.startAnimating()
self.navigationItem.rightBarButtonItem = UIBarButtonItem(customView: uiBusy)

这将覆盖 rightBarButtonItem 的纺车。当你完成后,只需重新创建 rightBarButtonItem

This overwrites your rightBarButtonItem with the spinning wheel. When you're done, just recreate the rightBarButtonItem.

这篇关于添加UIActivityIndi​​catorView到UIBarButton的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆