I'd like to display a UIActivityView in a rounded transparent box with text, just like the one shown below. Does anyone know how to do this?
p.s. I'd rather not be putting it in an UIAlertView开发者_如何学JAVA, but I don't know how to do it any other way.
Thanks!
TristanSure, create a new UIView subclass, call it whatever you like. Add a couple of ivars, one for your activity indicator, and one for your message (so a UIActivityIndicatorView
and a UILabel
). Connect those up to properties if you wish, probably a good idea for the label anyway.
You'll also want to define some methods, things like -show
and -hide
to show the view and hide it. You can get fancy animating it however you want, if you want, I'm not going to go into that here.
Next thing you'll want to do (or at least how I've done it) is to create the view, by specing out its frame, let's just define it like this:
UIWindow* keyWindow = [[UIApplication sharedApplication] keyWindow];
CGFloat width = 160;
CGFloat height = 160;
CGRect centeredFrame = CGRectMake(round(keyWindow.bounds.size.width/2 - width/2),
round(keyWindow.bounds.size.height/2 - height/2),
width, height);
This will make it 160x160. Adjust its backgroundColor
to 50% opacity, make sure its opaque
property is also set to NO. You'll also want something like:
self.layer.cornerRadius = 10;
where self
points at the view you're creating naturally.
That should be enough information to get you started, most people animate it (I typically make it really big, i.e., 160x2 by 160x2, and rapidly shrink it down to the size I want, to give it a popping effect, fade it out on completion, stuff like that). I'll leave that as an exercise for you though.
精彩评论