ios iPhone 上的大活动指示器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3490991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Big activity indicator on iPhone
提问by Yazzmi
Does anyone know how to show a rounded squared with a spinning activity indicator? It is used in many apps. If you don't know what im talking about, it looks like the indicator when you change volume on your Mac but with a darker background. Im not sure if it is built-in to iOS or someone made it.
有谁知道如何用旋转活动指示器显示圆角平方?它在许多应用程序中使用。如果您不知道我在说什么,当您在 Mac 上更改音量但背景较暗时,它看起来像指示器。我不确定它是内置于 iOS 还是有人制作的。
Like the one in this post but not full screen just the activity indicator How to create a full-screen modal status display on iPhone?
就像这篇文章中的那个,但不是全屏只是活动指示器 如何在 iPhone 上创建全屏模式状态显示?
回答by guirto
Here's what I use when I want to show that kind of indicators.
当我想显示这种指标时,我会使用以下方法。
UIView *loading = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 120, 120)];
loading.layer.cornerRadius = 15;
loading.opaque = NO;
loading.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.6f];
UILabel *loadLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 25, 81, 22)];
loadLabel.text = @"Loading";
loadLabel.font = [UIFont boldSystemFontOfSize:18.0f];
loadLabel.textAlignment = UITextAlignmentCenter;
loadLabel.textColor = [UIColor colorWithWhite:1.0f alpha:1.0f];
loadLabel.backgroundColor = [UIColor clearColor];
[loading addSubview:loadLabel];
[loadLabel release];
UIActivityIndicatorView *spinning = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinning.frame = CGRectMake(42, 54, 37, 37);
[spinning startAnimating];
[loading addSubview:spinning];
[spinning release];
loading.frame = CGRectMake(100, 200, 120, 120);
Then you just add the 'loading' view to the view of your choice and you got it.
然后您只需将“加载”视图添加到您选择的视图中即可。
Hope this is what you needed.
希望这是你所需要的。
回答by Dan Ray
Your screenshot is probably a usage of David Sinclair's DSActivityView module. Specifically, the DSBezelActivityView component of it. Or if not, it's a close copy.
您的屏幕截图可能是 David Sinclair 的 DSActivityView 模块的用法。具体来说,就是它的 DSBezelActivityView 组件。或者,如果没有,它就是一个接近的副本。
http://www.dejal.com/developer/dsactivityview
http://www.dejal.com/developer/dsactivityview
I use DSActivityView all the time. Great library. Toss that thing up while pulling down data, keeps users and clients happy.
我一直使用 DSActivityView。很棒的图书馆。在拉取数据的同时抛出那个东西,让用户和客户满意。
回答by jtbandes
One option: MBProgressHUD.
一种选择:MBProgressHUD。
回答by Dejal
I don't think that screenshot is my DSBezelActivityView; the metrics look a little different. But it is very similar.
我不认为那个截图是我的DSBezelActivityView;指标看起来有点不同。但它非常相似。
Note, DSActivityView and its subclasses don't use any images or nibs; they're pure code.
注意,DSActivityView 及其子类不使用任何图像或笔尖;它们是纯代码。
To answer the original question, it'd be easy to modify DSBezelActivityView to omit the fullscreen gray background. You could do it by subclassing and overriding the -setupBackground
method thusly:
要回答最初的问题,很容易修改 DSBezelActivityView 以省略全屏灰色背景。您可以通过子类化和覆盖该-setupBackground
方法来做到这一点:
- (void)setupBackground;
{
[super setupBackground];
self.backgroundColor = [UIColor clearColor];
}
Hope this helps!
希望这可以帮助!
回答by Rajesh Loganathan
Try this simple method, Its working well for me....
试试这个简单的方法,它对我来说效果很好......
UIActivityIndicatorView *activityIndicator= [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
activityIndicator.layer.cornerRadius = 05;
activityIndicator.opaque = NO;
activityIndicator.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.6f];
activityIndicator.center = self.view.center;
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
[activityIndicator setColor:[UIColor colorWithRed:0.6 green:0.8 blue:1.0 alpha:1.0]];
[self.view addSubview: activityIndicator];
回答by Shinohara
You're actually looking at using two UIView subclasses and a custom .png image to get the look you want. The Gray translucent box would be a UIImageView object, to get the effect you're looking for you need a .png file of a grey square with rounded corners, it doesn't need to be the final size, as long as there's at least one pixel of straight edge between the corners it will work fine. You'll then load it in as a UIImage with the UIImage stretchableImageWithLeftCapWidth:topCapHeight: method, this let's you specify the top, and left portions of the image that must stay the same, and a 1 pixel slice in each direction will be stretched out to fill the UIImage view you use the image in. http://www.bit-101.com/blog/?p=2275has a great example of how this works. So create a UIImage, then create a UIImageView using this image, set its opaque property to NO and the alpha property to something that looks good to you. Add this a subview of your current view. Now you just need to add the spinning progress indicator, this is even easier, just create a new UIActivityIndicatorView and add it as a subview of the UIImageView you've already created. The same basic method is used to create pretty much any resizable element in an iOS application. There's some examples of using them for buttons in Apple's UICatalog example code.
您实际上正在考虑使用两个 UIView 子类和一个自定义 .png 图像来获得您想要的外观。灰色半透明框将是一个 UIImageView 对象,要获得您正在寻找的效果,您需要一个带圆角的灰色正方形的 .png 文件,它不需要是最终大小,只要至少有角之间的直边的一个像素将正常工作。然后你将它作为 UIImage 加载到 UIImage 中,使用 UIImage 拉伸ImageWithLeftCapWidth:topCapHeight: 方法,这让你指定图像的顶部和左侧部分必须保持不变,并且每个方向上的 1 像素切片将被拉伸填充您使用图像的 UIImage 视图。http://www.bit-101.com/blog/?p=2275有一个很好的例子来说明这是如何工作的。因此,创建一个 UIImage,然后使用此图像创建一个 UIImageView,将其 opaque 属性设置为 NO,将 alpha 属性设置为对您来说看起来不错的东西。将此添加为当前视图的子视图。现在您只需要添加旋转进度指示器,这更容易,只需创建一个新的 UIActivityIndicatorView 并将其添加为您已经创建的 UIImageView 的子视图。相同的基本方法用于在 iOS 应用程序中创建几乎所有可调整大小的元素。在 Apple 的 UICatalog 示例代码中有一些将它们用于按钮的示例。