Connecting UIActivityIndicator to UIButton

New to all this Xcode stuff. I have several UIButton that link to movies and music files from my website - they work great, it's just that there is some time delay when loading MoviePlayer, where it seems like nothing is happening.

I would like to set up a UIActivityIndicator - I cannot sem find an easy way to do this.

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

Could you help me? Thanks Carl

+3
source share
2 answers

If you want to add an ActivityIndicator directly to your button, here is the code for 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];

, , , .

+9

, - , , , stopAnimating, , .

IB, IBOutlet, , /.

+1

Source: https://habr.com/ru/post/1710969/


All Articles