Ячейка UITableView с фоновым изображением
У меня есть UITableView, где есть 3 изображения.
1 для выбранной ячейки, 1 для фона ячейки и 1 для фона TableView.
Моя выбранная ячейка работает нормально, но имеет некоторые проблемы с нормальными ячейками и фон TableView (фон за ячейками при прокрутке вниз/вверх до большого количества)
Может ли кто-нибудь помочь мне с фоном для каждой ячейки и фон TableView? как это делается?
Нормальный фон ячейки: (не уверен, что его право)
// CELL BACKGROUND-IMAGE
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_normal.PNG"]];
Выбранный фон ячейки:
// SELECTED CELL BACKGROUND-IMAGE
UIView *viewSelected = [[[UIView alloc] init] autorelease];
viewSelected.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"cell_highlighted.PNG"]];
cell.selectedBackgroundView = viewSelected;
Ответы
Ответ 1
Для ячейки
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] ];
Для Tableview
[mEditTableView setBackgroundView:nil];
[mEditTableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"apple.png"]] ];
Ответ 2
Вы можете установить UITableViewCell
фон цвет/изображение, выбрав метод делегата
- (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
}
Ответ 3
В быстром режиме вы можете установить фоновое изображение в UITableViewCell, как показано ниже.
cell.backgroundView = UIImageView(image: UIImage(named: "yourImage.png")!)
Введите этот код в эту функцию в виде таблицы.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
Это изображение будет повторяться в каждой строке.
Ответ 4
это устанавливает фон для tableView, а не ячейки
// CELL BACKGROUND-IMAGE
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_normal.PNG"]];
попытайтесь получить set cellbackground в cellForRowAtIndexPath
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_normal.PNG"]];
Ответ 5
Вы можете попробовать этот код блока для установки фонового изображения 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];
Надеется, что это сработает для вас.:)
Ответ 6
установить изображение в ячейке UITableview
cell.imageView.image = [UIImage imageNamed: @ "image.png" ];
Ответ 7
Только это решение получилось для меня.
Cell.backgroundColor = [UIColor clearColor];
Cell.contentView.backgroundColor=[UIColor clearColor];
Надеюсь, это поможет!
Ответ 8
//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];
}