unable to show activity indicator iOS - ios

i am trying to show UIActivityIndicator on viewDidLoad of a screen. its working in another project but not sure why it's not displayed here.
I am calling the showSplashScreen fromviewDidLoad of other screen.
+(void) showSplashScreen
{
UIView *mainScreen = [[[UIApplication sharedApplication]delegate]window];
UIView *windowBlocker = [[UIView alloc]initWithFrame:mainScreen.frame];
windowBlocker.tag = 999;
windowBlocker.backgroundColor = [UIColor clearColor];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((mainScreen.frame.size.width), (mainScreen.frame.size.height), 50, 50)];
imageView.layer.backgroundColor=[[UIColor colorWithRed:200 green:0 blue:0 alpha:0.5] CGColor];
imageView.layer.cornerRadius=10;
imageView.layer.masksToBounds = YES;
[windowBlocker addSubview:imageView];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[windowBlocker addSubview:spinner];
spinner.center = mainScreen.center;
[spinner startAnimating];
}
nothing happens. Any idea? I am trying for iPad.

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[imageView addSubview:spinner];
spinner.center = mainScreen.center;
[windowBlocker addSubview:imageView];
[self.view addSubview: mainScreen];
[spinner startAnimating];

//Yoy forget to add windowBlocker in mainview
[Self.view addSubview:windowBlocker];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = mainScreen.center;
[spinner startAnimating];
[windowBlocker addSubview:spinner];
//Try this code

looks like the issue is that you haven't added windowBlocker to the screen.
try:
[mainScreen addSubview:windowBlocker];

-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self performSelector:#selector(addSplash) withObject:nil afterDelay:0.5];
}
-(void)addSplash {
[[self class] showSplashScreen];
}
+(void) showSplashScreen
{
UIView *mainScreen = [[[UIApplication sharedApplication]delegate]window];
UIView *windowBlocker = [[UIView alloc]initWithFrame:mainScreen.frame];
windowBlocker.tag = 999;
windowBlocker.backgroundColor = [UIColor redColor];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((mainScreen.frame.size.width), (mainScreen.frame.size.height), 50, 50)];
imageView.layer.backgroundColor=[[UIColor colorWithRed:200 green:0 blue:0 alpha:0.5] CGColor];
imageView.layer.cornerRadius=10;
imageView.layer.masksToBounds = YES;
[windowBlocker addSubview:imageView];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[windowBlocker addSubview:spinner];
spinner.center = mainScreen.center;
[spinner startAnimating];
[[[[UIApplication sharedApplication]delegate]window] addSubview:windowBlocker];
}
As I added some delay with 0.5 because when i called function in ViewDidLoad orViewWillAppear some reason view not initaliaze yet so i provide some delay or you can use the viewDidAppear for as an option of this situation like and only this function and remove viewWillAppear and addSplash and add only this
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[self class] showSplashScreen];
}

Change this ... it works for you
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.color=[UIColor greenColor];
spinner.center = self.view.center;
[spinner startAnimating];
[windowBlocker addSubview:spinner];

Related

add UIView loading screen on top window of application in objective c

I am trying to add an UIView with a UIActivityIndicatorView does not seem to work. Any help appreciated.
UIView *overlayView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
overlayView.backgroundColor = [UIColor colorWithRed:255 green:255 blue:255 alpha:1];
UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.center = overlayView.center;
[overlayView addSubview:activityIndicator];
[activityIndicator startAnimating];
UIWindow *keyWindow = [[[UIApplication sharedApplication] delegate] window];
[keyWindow addSubview:overlayView];
Trying also adding it like this
[self.navigationController.view addSubview:overlayView];
[self.navigationController.view bringSubviewToFront:overlayView];
seems to work but the navigationbar is not getting hidden
It is possible to add an overlay to a current shown controller like this:
- (void)viewDidAppear:(BOOL)animated; {
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
overlayView.backgroundColor = [UIColor blackColor];
overlayView.alpha = 0.8;
[self.view.window addSubview:overlayView];
}
This overlay should cover all the current window.
In your viewcontroller class, use the following code to display your overlay view.
UIView *overlayView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[overlayView setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.7]];
[self.view.window addSubview:overlayView];
The key here is to use viewcontroller's view's window object so that in case of NavigationController or TabBarController, complete view is overlaid along with navigation bar and or tab bar.

how to remove subview from class method in ios?

I have an app.In this app so many class methods used.I want to know is it possible to remove subview from class mehtod?
+(void)addPregressIndicator:(NSString *)strText view:(UIView *)ShowView
{
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
UIView *busyView = [[UIView alloc] initWithFrame:appFrame];
busyView.backgroundColor = [UIColor clearColor];
busyView.opaque = YES;
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 95, 95)];
container.layer.borderWidth = 5;
container.layer.cornerRadius = 10;
container.layer.borderColor = [UIColor whiteColor].CGColor;
[container setBackgroundColor:[UIColor blackColor]];
UIActivityIndicatorView *av = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
av.center = CGPointMake(container.center.x, 34);
av.hidesWhenStopped = NO;
[av startAnimating];
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 95, 30)];
lbl.text = strText;
lbl.textAlignment = NSTextAlignmentCenter;
lbl.center = CGPointMake(container.center.x, 70);
lbl.textColor = [UIColor whiteColor];
lbl.backgroundColor = [UIColor clearColor];
[container addSubview:av];
[container addSubview:lbl];
container.center = busyView.center;
[busyView addSubview:container];
[ShowView addSubview:busyView];
}
+(void)removePregressIndicator:(UIView *)hideView;
{
// i want remove busyview that subview in viewcontroller.
}
Please help me to remove subivew.
You can set a unique tag for the busyView like this busyView.tag = your unique tag;
And then you can remove the view with this code
+(void)removePregressIndicator:(UIView *)hideView;
{
UIView *busyView = [hideView viewWithTag:your unique tag];
if (busyView){
[busyView removeFromSuperview];
}
}
You should make sure that the busyView tag is unique for all the subviews of hideView.
Assigne tag to a each view and access the view with tag and put it
+(void)removePregressIndicator:(UIView *)hideView;
{
UIView *viewToRemove = [self.view viewWithTag:assigne_tag];
[viewToRemove removeFromSuperview];
}
+ (void)removePregressIndicator:(UIView *)hideView;
{
UIView *progView=[self.view viewWithTag:YourTag];
[progView removeFromSuperview];
}

Custom UIActivityViewController with backgroundColor

How can I set color of bottom view with all elements of UIActivityViewController?
My current implementation changes color for all view -
CopyLink *copyLink = [[CopyLink alloc]init];
copyLink.delegate = self;
self = [self initWithActivityItems:#[emailActivity] applicationActivities:#[copyLink]];
self.view.backgroundColor = [UIColor redColor];
self.completionHandler = ^(NSString *activityType, BOOL completed)
You can't do this, the UIActivityViewController is supposed to take form of an overlay sheet, I doubt you can even access the view of it let alone its background colour, You may have to create a custom Subview and then use that as the subview
Here is the best way to use UIActivityViewController :
-(void)doStartStopSpinner
{
if (![spinner isAnimating])
{
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
spinner.center = self.view.center;
spinner.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.6];
[self.view addSubview:spinner];
[spinner startAnimating];
}
else
{
[spinner stopAnimating];
[spinner removeFromSuperview];
[viewUpgradePro removeFromSuperview];
}
}
Hope it'll help.

Activity Indicator is not showing on images

Hi I'm trying to upload image's from iphone to server in that i given activity indicator for the user to known that image is uploading while clicking upload it will show activity indicator for few minutes.
But my problem is the activity indicator only showing in few images its not showup on all the images pls tell me how to resolve this.
my activity coding .
-(void)temp{
spinner = [[UIActivityIndicatorView alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
//spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:]
spinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
[spinner setCenter:CGPointMake(160, 240)]; // (mid of screen) I do this because I'm in landscape mode
[self.view addSubview:spinner];
spinner.color = [UIColor blackColor];
spinner.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.4];
[spinner startAnimating];
[spinner release];
}
-(void) myMethod{
[spinner stopAnimating];
spinner.hidden = YES;
spinner.color = [UIColor yellowColor];
}
- (IBAction)pushUpload:(id)sender {
[self temp];
[self performSelector:#selector(myMethod) withObject:nil afterDelay:5.0f];
}
Instead of ActivityIndicator use AsynchronousImageView It will automatically add activityindicator while loading an image.
[AsynObj loadImageFromURL:[NSURL URLWithString:ImageUrl]];
You can get the AsyncImageView classes from the following link https://github.com/nicklockwood/AsyncImageView
I hope it will help!

How can i add a stylish white color uialertview with activity indicator

when i press one button i have to display one white color uialertview with activity indicator for 5 seconds ?
i saw some codes and i select the following code ,is that enough? how can i change the color of activity indicator
myAlertView = [[UIAlertView alloc] initWithTitle:#"Loading" message:#"\n\n"
delegate:self
cancelButtonTitle:#""
otherButtonTitles:#"OK", nil];
UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
loading.frame=CGRectMake(150, 150, 16, 16);
[myAlertView addSubview:loading];
i want something like in this image with uiactivity indicator
You can create a custom alert like follow (PS: i had developed this custom alert after 3 hours of working, its compatible with iPhone4, iPhone5 and iPad ):
-(void)showAlert{
alertViewView = [[UIView alloc]initWithFrame:self.window.frame];
UIImageView *alertBackground = [[UIImageView alloc]initWithFrame:CGRectMake(-200, -200, self.window.frame.size.width*2, self.window.frame.size.height*2)];
// alertBackground.image = [UIImage imageNamed:#"alertBackGround.png"];
[alertViewView addSubview:alertBackground];
alertBackground.backgroundColor = [UIColor blackColor];
alertBackground.alpha = 0.5;
UIImageView *alertImage = [[UIImageView alloc]initWithFrame:CGRectMake(self.window.frame.size.width/2-310/2, self.window.frame.size.height/2-179/2, 310, 248)];
alertImage.image = [UIImage imageNamed:#"rommanAlertBig.png"];
[alertViewView addSubview:alertImage];[alertBackground release];[alertImage release];
UIButton *lButton = [UIButton buttonWithType:UIButtonTypeCustom];
lButton.frame = CGRectMake(self.view.frame.size.width/2-150+40-15, self.view.frame.size.height/2-179/2+118 , 120, 41);
[lButton setTitle:#"Cancel" forState:UIControlStateNormal];
[lButton addTarget:self action:#selector(removeAlert) forControlEvents:UIControlEventTouchUpInside];
[alertViewView addSubview:lButton];
UIButton *rButton = [UIButton buttonWithType:UIButtonTypeCustom];
rButton.frame = CGRectMake(self.view.frame.size.width/2-150+170-15, self.view.frame.size.height/2-179/2+118 , 120, 41);
[rButton setTitle:#"OK" forState:UIControlStateNormal];
[rButton addTarget:self action:#selector(yesAction) forControlEvents:UIControlEventTouchUpInside];
[alertViewView addSubview:rButton];
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(self.window.frame.size.width/2-310/2+30, self.window.frame.size.height/2-179/2+75, 260, 40+69)];
lbl.text = #"Description";
lbl.textColor = [UIColor whiteColor];
lbl.textAlignment =UITextAlignmentCenter;
lbl.numberOfLines = 0;
lbl.font = [UIFont systemFontOfSize:17.0];
lbl.backgroundColor = [UIColor clearColor];
[alertViewView addSubview:lbl];[lbl release];
[self.window addSubview:alertViewView];
alertViewView.alpha = 0;
[UIView animateWithDuration:0.1 animations:^{alertViewView.alpha = 1.0;}];
alertViewView.layer.transform = CATransform3DMakeScale(0.5, 0.5, 1.0);
CAKeyframeAnimation *bounceAnimation = [CAKeyframeAnimation animationWithKeyPath:#"transform.scale"];
bounceAnimation.values = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.5],
[NSNumber numberWithFloat:1.1],
[NSNumber numberWithFloat:0.8],
[NSNumber numberWithFloat:1.0], nil];
bounceAnimation.duration = 0.3;
bounceAnimation.removedOnCompletion = NO;
[alertViewView.layer addAnimation:bounceAnimation forKey:#"bounce"];
alertViewView.layer.transform = CATransform3DIdentity;
}
-(void)removeAlert{
for (UIView *v in [alertViewView subviews]) {
[v removeFromSuperview];
}
[alertViewView removeFromSuperview];
[alertViewView release];
}
-(void)yesAction
{ [self removeAlert];
// Your Code here
}
Change color of activity indicator
In iOS 5.0 and up you can use setColor: on the UIActivityIndicatorView to set a custom color.
MAke a custom alertview
make a subclass
In drawrect draw white color on top of the view part
Why not use the class you took the picture from? https://github.com/m1entus/WCAlertView
For the ActivityIndicator you can just drag one out with the IB and change its color. Then do something like :
[activityindicator startanimating];
//put alert code here
// choose when you want to stop the animation:
//[activityindicator stopanimating];

Resources