UIActivityIndicatorView inside UIButton

2019-08-14 03:58发布

问题:

I have a couple of programmatically generated UIButtons (custom, 200 by 200, white background) where i wanted to put a UIActivityIndicatorView inside. I tried it with the following code:

UIActivityIndicatorView *playlistImageLoader = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
playlistImageLoader.center = CGPointMake(100, 100);
playlistImageLoader.hidesWhenStopped = YES;

[playlistImage addSubview:playlistImageLoader];
[mainScrollView addSubview:playlistImage];

[playlistImageLoader startAnimating];

But it doesn't show up? Have any ideas?

thanks!

回答1:

You didn't set the indicator frame, set it and it will be alright to have it as a button subview.

Try to use UIActivityIndicatorViewStyleGray - UIActivityIndicatorViewStyleWhite is invisible on the white background.