I\'ve now added a bounty which will be awarded to anyone who can take the three images below and produce a working implementation of a UITableView that mimicks the l
They are removing all of the default drawing/borders and simply using custom cells with their own images.
Regarding your edit: This is incorrect. I've achieved that behavior too. , before, I don't recall exactly how I did it, I think I set the background image directly on the table view, not the view behind it. (See the code below.)
EDIT:
Here's the code I used to mimic the behaviour of cells "dragging" portions of the background with them:
- (void)viewDidLoad {
[super viewDidLoad];
[self.tableView setRowHeight:65.0];
[self.tableView setBackgroundColor:[UIColor clearColor]];
[self.tableView setBackgroundView:nil];
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"metal_settings.png"]]];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[self setContentSizeForViewInPopover:CGSizeMake(300, 300)];
}
I've put this in a UITableViewController subclass and have inherited from that in several instances. If you look closely, the "color"/texture outside of the cells moves with the cells.
I'm not sure to answer exactly what you asked for because I used a grouped tableView, but when testing it seems to do the trick, and the background scrolls with the cells, as it can be seen in game center.
By the way, sorry, I don't use objective C but Monotouch and C#, but I know from experience it's not so hard to find bindings from one to the other when finding an interesting trick written in another language.
Well, stop babbling, here's the code.
public class test : UIScrollView {
UIImage _borderTexture = null;
int _paddingTop = 10;
public test (RectangleF frame) : base (frame) {
//setting the green background for the whole view
BackgroundColor = UIColor.FromPatternImage(new UIImage("bg.png"));
//initializing texture for borders
_borderTexture = new UIImage("bt.png");
//adding some various-sized tables
addTable(new string[] {"lonely cell"});
addTable(new string[] {"top cell", "middle cell 1", "middle cell 2", "bottom cell"});
addTable(new string[] {"this", "is", "a", "quite", "long", "table", "for", "an", "exemple"});
//and then we adjust the scroll size to contents
ContentSize = new SizeF(frame.Size.Width, _paddingTop);
}
void addTable(string[] contents) {
// approximately keeping track of content's heights to adjust scrollView size
// the table must be AT LEAST as high as its content to avoid its own scroll
int approximativeHeight = contents.Length * 44 + 25;
UITableView t = new UITableView(new RectangleF(10, _paddingTop, Frame.Width - 20, approximativeHeight), UITableViewStyle.Grouped);
_paddingTop += approximativeHeight;
//make the tableView's background invisible
t.BackgroundColor = UIColor.FromWhiteAlpha(0, 0);
//setting the yellow texture for cell borders
t.SeparatorColor = UIColor.FromPatternImage(_borderTexture);
//using our own data source to customize cells at creation
t.DataSource = new testTVDataSource(contents);
//finally, add the custom table to the scroll view
AddSubview(t);
}
}
public class testTVDataSource : UITableViewDataSource {
string[] _contents = null;
string _cellID = "reuse";
public testTVDataSource(string[] contents) {
_contents = contents;
}
public override int RowsInSection (UITableView tableView, int section) {
return _contents.Length;
}
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath) {
var cell = tableView.DequeueReusableCell (_cellID);
if (cell == null) {
cell = new UITableViewCell (UITableViewCellStyle.Default, _cellID);
//make all backgrounds of the cell and its subviews to be invisible
cell.BackgroundColor = UIColor.FromWhiteAlpha(0, 0);
cell.TextLabel.BackgroundColor = UIColor.FromWhiteAlpha(0, 0);
//avoid the blue highlighting when selected
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
}
//just some content for test
cell.TextLabel.Text = _contents[indexPath.Row];
return cell;
}
}
So the main tweak resides in making your tableView transparent and high enough for it to not need scrolling, and to stick it into a scrollView which will scroll its background with its content (here, the tableViews.)