I am trying to set a custom background for the rows of a grouped UITableView
and I have absolutely no idea how to achieve that.
The table design I am trying to apply on my table looks like this:
And I have sliced it into 3 cell types: top, middle and bottom. How can I apply the custom background for each of the table's cells?
You can set UIImageView
as cell backgroundView
for first, middle and last cell in function:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
Check good (and simple) example at: http://www.planet1107.net/blog/tips-tutorials/custom-grouped-cell-tutorial/
In cellForRowAtIndexPath
, check the type of current row and then assign the corresponding background to it.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Create cell
// ...
// Configure cell
switch (cellType) {
case TOP:
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"top.png"]];
break;
case MIDDLE:
...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With