I’ve this code for adding UIActivityIndicatorView to a UITableViewCell.
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
UIImage *spacer = [UIImage imageNamed:@"spacer"];
UIGraphicsBeginImageContext(CGSizeMake(220, 150));
[spacer drawInRect:CGRectMake(0,0,spinner.frame.size.width,spinner.frame.size.height)];
UIImage* resizedSpacer = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cell.imageView.image = resizedSpacer;
[cell.imageView addSubview:spinner];
[spinner startAnimating];
Currently the image is shown in the top left of the 220×150 box. Instead I would like to put it in center. How can I do that? I’ve tried to change the two first parameters on CGRectMake, but that didn’t change anything.
You’ve added
resizedSpaceras the imageView without actually doing anything tospinner‘s frame. You want something like:I don’t think that the logic involving
spaceris required. In fact, you may not even want to host theUIActivityIndicatorViewin theUIImageViewat all; why not position it directly within the tableview cell?