Curnelious
Curnelious

Reputation: 1

Removing activity indicator from its rect?

I am using this code to show activity indicator :

    UIActivityIndicatorView  *av = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
    av.frame=CGRectMake(0.5*winSize.width-winSize.width/4, 0.80*winSize.height , winSize.width/2, winSize.width/8);
    [av setBackgroundColor:[UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:0.75]];
    av.layer.cornerRadius=4;
    av.tag  = 31000;
    [[[CCDirector sharedDirector]view]addSubview:av];
    [av startAnimating];

and to remove it :

UIActivityIndicatorView *tmpimg = (UIActivityIndicatorView *)[[[CCDirector sharedDirector]view] viewWithTag:31000];
    if(tmpimg)
        [((UIView *)tmpimg) removeFromSuperview];

What i need is to remove only the indicator itself(the circle that rolling) and leave the rect of his view that i just draw (av.frame) .

How would i do that ? Thanks a lot .

Upvotes: 1

Views: 240

Answers (3)

Nirav Gadhiya
Nirav Gadhiya

Reputation: 6342

For adding use this........

UIView * aView = [[UIView alloc] initWithFrame:CGRectMake(0.5*winSize.width-winSize.width/4, 0.80*winSize.height , winSize.width/2, winSize.width/8)];
aView.backGroundColor = [UIColor clearColor];
aView.tag  = 31000;
UIActivityIndicatorView  *av = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
av.frame=aView.bounds;
[av setBackgroundColor:[UIColor colorWithRed:0.23 green:0.23 blue:0.23 alpha:0.75]];
av.layer.cornerRadius=4;

[aView addSubview:av];
[[[CCDirector sharedDirector]view]addSubview:aView];
[av startAnimating];

And for remove use this

UIView * aView = [[[CCDirector sharedDirector]view] viewWithTag:31000];
if(aView)
{
    [aView removeFromSuperview];
}

Upvotes: 1

x4h1d
x4h1d

Reputation: 6092

In that case what you can do is set

av.hidesWhenStopped = YES;

It will hide the indicator when it stops. I don't think you need to remove it.

Upvotes: 1

Avi Tsadok
Avi Tsadok

Reputation: 1843

You can't.

Build a some custom UIView that holds the background + corner radius, and holds the activity indicator as well.

After that, you can add a method to this custom UIView that hides/remove the activity indicator.

By the way, you can just hide the activity indicator, or stop it (if hidesWhenStopped is YES, it will be much efficient than creating activity indicator every time).

Upvotes: 1

Related Questions