How to use custom background for grouped UITableView cells?

I am trying to set my own background for rows of a grouped UITableView , and I don't know how to do this.

The design of the table I'm trying to apply to the table is as follows:

Custom Designed Grouped UITableView

And I cut it into 3 types of cells: top , middle and bottom . How can I apply a custom background to each of the table cells?

+4
source share
6 answers

You can set UIImageView as backgroundView cell for the first, middle and last cell in a function:

 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 

Check out a good (and simple) example: http://www.planet1107.net/blog/tips-tutorials/custom-grouped-cell-tutorial/

+6
source

In cellForRowAtIndexPath check the type of the current row, and then assign it the appropriate background.

 - (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: ... } } 
+4
source

Ray Wenderlich has a very good tutorial on how to do this with Core Graphics: http://www.raywenderlich.com/2033/core-graphics-101-lines-rectangles-and-gradients

+2
source

This tutorial will give you exactly what you are looking for.

http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html

+1
source

UITableViewCell has a backgroundView property. Set this value in tableView: cellForRowAtIndexPath: -method.

https://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewCell_Class/Reference/Reference.html

0
source

Instead of assigning a separate image for each, create one custom cell and assign a background image since the cell is higher. And the Crop above the image, in addition to the internal cells, assign this one to the background view of the UITableView (Plain table view), that is, you do not need to create grouped tables.

0
source

Source: https://habr.com/ru/post/1399137/


All Articles