public override UITableViewCell GetCell (UITableView tv) { var cell = tv.DequeueReusableCell (key); UIActivityIndicatorView activityIndicator; ImageButton imageButton; if (cell == null) { cell = new UITableViewCell (UITableViewCellStyle.Default, key); activityIndicator = new UIActivityIndicatorView () { ActivityIndicatorViewStyle = UIActivityIndicatorViewStyle.Gray, Tag = 1 }; imageButton = new ImageButton(new RectangleF(0, 0, 0, 0)) { ContentMode = UIViewContentMode.Center, Tag = 3 }; imageButton.TouchUpInside+= HandleGlassButtonTouchUpInside; cell.ContentView.AddSubview(imageButton); cell.ContentView.AddSubview (activityIndicator); } else { activityIndicator = cell.ContentView.ViewWithTag (1) as UIActivityIndicatorView; imageButton = cell.ContentView.ViewWithTag(3) as ImageButton; } if (Animating) { activityIndicator.Hidden = false; activityIndicator.StartAnimating (); } else { activityIndicator.Hidden = true; activityIndicator.StopAnimating (); } if (BackgroundColor != null) { cell.ContentView.BackgroundColor = BackgroundColor ?? UIColor.Clear; } else { cell.ContentView.BackgroundColor = null; } imageButton.BackgroundColor = UIColor.Clear; Layout (cell, activityIndicator, imageButton); return cell; }
void Layout (UITableViewCell cell, UIActivityIndicatorView activityIndicator, ImageButton button) { var sbounds = cell.ContentView.Bounds; if (!activityIndicator.Hidden) { activityIndicator.Frame = new RectangleF ((sbounds.Width - _Image.Size.Width) / 2 ,10, _Image.Size.Width, _Image.Size.Height); } else { button.BackgroundColor = UIColor.Clear; button.SetTitle ("", UIControlState.Normal); button.NormalColor = UIColor.Clear; button.DrawImage = true; button.Frame = new RectangleF ((sbounds.Width - _Image.Size.Width) / 2 ,10, _Image.Size.Width, _Image.Size.Height); button.SetBackgroundImage(_Image, UIControlState.Normal); } }