Komórka UITableView z obrazem tła

Mam UITableView, gdzie są 3 obrazy. 1 dla wybranej komórki, 1 dla tła komórki i 1 dla tła widoku TableView.

Moja wybrana Komórka działa dobrze, ale mam pewne problemy z normalnymi komórkami i tłem TableView(tłem za komórkami, gdy przewijasz w dół/w górę do dużo)

Czy ktoś może mi pomóc z tłem dla każdej komórki i tłem TableView ? jak to się robi ?

Normalne tło komórki: (Nie wiem czy jego prawo)

// CELL'S BACKGROUND-IMAGE
    self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_normal.PNG"]];

Tło Wybranej Komórki:

// SELECTED CELL'S BACKGROUND-IMAGE
    UIView *viewSelected = [[[UIView alloc] init] autorelease];
    viewSelected.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"cell_highlighted.PNG"]];
    cell.selectedBackgroundView = viewSelected;
Author: Patrick R, 2011-06-13

9 answers

Dla Komórki

    cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"cell_normal.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];  
    cell.selectedBackgroundView =  [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"cell_pressed.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];

Dla Tableview

    [mEditTableView setBackgroundView:nil];
    [mEditTableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"apple.png"]] ];
 143
Author: Naveen Thunga,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-03-06 08:37:59

Możesz ustawić UITableViewCell Tło kolor/obraz , stosując metodę delegate

 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath
 *)indexPath  
{      
     if((indexPath.row)==0)  
       cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_normal.PNG"]]; //set image for cell 0

     if (indexPath.row==1)  
       cell.backgroundColor = [UIColor colorWithRed:.8 green:.6 blue:.6 alpha:1]; //set color for cell 1

     tableView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"cloud.jpg"]]; //set image for UITableView

  }
 10
Author: iPatel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-09-02 04:35:06

W języku swift możesz ustawić obraz tła na UITableViewCell jak poniżej.

cell.backgroundView = UIImageView(image: UIImage(named: "yourImage.png")!)

Zapisz ten kod w tej funkcji widoku tabeli.

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 

Ten obrazek będzie powtarzał się w każdym rzędzie.

 4
Author: Vikram Pote,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-10-08 05:55:57

Ustawia tło dla widoku tabeli, a nie komórki

// CELL'S BACKGROUND-IMAGE
    self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_normal.PNG"]];

Spróbuj ustawić cellbackground w cellForRowAtIndexPath

 cell.backgroundColor =  [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_normal.PNG"]];
 2
Author: FoJjen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-06-13 11:33:41

W Swift 4 działa to:

cell.backgroundView = UIImageView.init(image: UIImage.init(named: "YORIMAGE.jpg"))
 1
Author: David DelMonte,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-01 20:06:50

Ustawianie obrazu w komórce UITableview

Komórka.imageView.image = [UIImage imageNamed:@ " image.png"];

 0
Author: Kiran Bhoraniya,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-02-06 09:27:05

Tylko to rozwiązanie mi się udało .

Cell.backgroundColor = [UIColor clearColor];
Cell.contentView.backgroundColor=[UIColor clearColor];
Mam nadzieję, że to pomoże !
 0
Author: user5553647,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-06-10 06:11:09

Możesz wypróbować ten kod bloku do Ustawienia obrazu tła UITableviewCell

self.backgroundView = [[[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"background.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0]] autorelease];

self.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"background_selected.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0]] autorelease];
Mam nadzieję, że ci się uda. :)
 0
Author: BHUPI,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-02-08 15:30:47
//this concept is right but one problem is create when ur fastly scroll in uitable View then cell background color slowly change and indexing problem 

for Cell

    UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame];
    myBackView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:0.75 alpha:1];
    cell.selectedBackgroundView = myBackView;
    [myBackView release];

for table

    aTableView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"cloud.jpg"]];
    aTableView.separatorStyle = UITableViewCellSeparatorStyleNone;

//this concept is right but one problem is cteare when ur fastly scroll in uitable View then cell background color slowly change and indexing problem  so use this code

for Cell


- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
   cell.backgroundColor = (indexPath.row%2)?[UIColor lightGrayColor]:[UIColor grayColor];
}
 -1
Author: Deepesh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-04-24 12:30:09