将 UIActivityIndi​​cator 连接到 UIButton

发布于 2024-07-25 01:34:37 字数 230 浏览 10 评论 0原文

对于所有这些 Xcode 东西来说都是新的 - 我有一些链接到电影和电影的 UIButton。 我的网站上的音乐文件 - 它们工作正常,只是在加载 MoviePlayer 时有一些滞后时间,看起来好像什么也没发生。

我想设置一个 UIActivityIndi​​cator - 我无法找到一个简单的方法来做到这一点。

如果是这样,我需要每个按钮一个吗?

你能帮忙吗? 谢谢卡尔

New to all this Xcode stuff - I have a few UIButton's that links to movie & music files from my web site - they works fine, it's just that there's some lag time while it's loading the MoviePlayer where it seems as if nothing's happening.

I would like to set up an UIActivityIndicator - I can't sem to find a simple way to do it.

And if so, would I need one for each button?

Could you help?
Thanks Carl

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如歌彻婉言 2024-08-01 01:34:37

如果您想将 ActivityIndi​​cator 直接添加到按钮,请使用以下一些代码来执行此操作:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(0,0,40,40); // increase width value if you want to add text   
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:@"location.png"] forState:UIControlStateNormal];

UIActivityIndicatorView *actIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
actIndicator.tag = 123456;
[actIndicator startAnimating];
actIndicator.frame = CGRectMake(7, 7, 26, 26);
[button addSubview:actIndicator];
[actIndicator release];

这显示了活动视图,但您可以在开头隐藏它,也可以通过其标签访问指示器来切换活动指示器。

If you want to add an ActivityIndicator directly to your button, here's some code to do this:

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(0,0,40,40); // increase width value if you want to add text   
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:@"location.png"] forState:UIControlStateNormal];

UIActivityIndicatorView *actIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
actIndicator.tag = 123456;
[actIndicator startAnimating];
actIndicator.frame = CGRectMake(7, 7, 26, 26);
[button addSubview:actIndicator];
[actIndicator release];

This shows the activity view, but you could either hide it in the beginning or toggle the activity indicator by accessing the indicator via its tag.

℡寂寞咖啡 2024-08-01 01:34:37

您创建一个活动指示器并将其放在屏幕上您喜欢的位置 - 然后您告诉它在您请求媒体时启动动画,并在收到播放已开始的回调时停止动画。

您可以通过编程方式或在 IB 中执行此操作,创建 IBOutlet,以便您可以告诉指标启动/停止。

You create an activity indicator and put it onscreen where you like - then you tell it to startAnimating when you request the media, and stopAnimating when you get a callback that the playback has begun.

You can do this programmatically or in IB, creating an IBOutlet so you can tell the indicator to start/stop.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文