Pat*_*k R 46 iphone background uitableview
我有一个UITableView,其中有3个图像.1表示所选单元格,1表示单元格背景,1表示TableView背景.
我选择的Cell,工作正常,但是正常单元格和TableView背景(当你向下滚动/向上滚动时,单元格背后的背景)存在一些问题
有人可以帮助我为每个单元格和TableView背景提供背景吗?怎么做的?
正常细胞背景:(不确定它是否正确)
// CELL'S BACKGROUND-IMAGE
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_normal.PNG"]];
Run Code Online (Sandbox Code Playgroud)
选定的细胞背景:
// SELECTED CELL'S BACKGROUND-IMAGE
UIView *viewSelected = [[[UIView alloc] init] autorelease];
viewSelected.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"cell_highlighted.PNG"]];
cell.selectedBackgroundView = viewSelected;
Run Code Online (Sandbox Code Playgroud)
Nav*_*nga 144
对于细胞
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] ];
Run Code Online (Sandbox Code Playgroud)
对于Tableview
[mEditTableView setBackgroundView:nil];
[mEditTableView setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"apple.png"]] ];
Run Code Online (Sandbox Code Playgroud)
小智 10
您可以按照委托方法设置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
}
Run Code Online (Sandbox Code Playgroud)
您可以迅速将背景图片设置为UITableViewCell,如下所示。
cell.backgroundView = UIImageView(image: UIImage(named: "yourImage.png")!)
Run Code Online (Sandbox Code Playgroud)
在表视图的此功能中编写此代码。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
Run Code Online (Sandbox Code Playgroud)
此图像将在每一行重复进行。
归档时间: |
|
查看次数: |
64716 次 |
最近记录: |