Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created January 6, 2011 05:18
Show Gist options
  • Save marshluca/767536 to your computer and use it in GitHub Desktop.
Save marshluca/767536 to your computer and use it in GitHub Desktop.
UIActivityIndicator as Accessory View
#define SPINNER_SIZE 25
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
// Get center of cell (vertically)
int center = [cell frame].size.height / 2;
// Size (width) of the text in the cell
CGSize size = [[[cell textLabel] text] sizeWithFont:[[cell textLabel] font]];
// Locate spinner in the center of the cell at end of text
[spinner setFrame:CGRectMake(size.width + SPINNER_SIZE, center - SPINNER_SIZE / 2, SPINNER_SIZE, SPINNER_SIZE)];
[[cell contentView] addSubview:spinner];
[spinner startAnimating];
[spinner release];
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIActivityIndicatorView *activityView =
[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[activityView startAnimating];
[cell setAccessoryView:activityView];
[activityView release];
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment