如何在 iPhone 的表格视图单元格中设置背景图像

发布于 2024-09-16 17:43:51 字数 232 浏览 4 评论 0原文

我想为单元格设置背景图像。我已经为表格视图中的单元格设置了背景图像。但我想在表视图单元格中设置两个图像作为背景图像。我想为背景设置备用单元格,

例如,

  Image1- Cell 1, Cell 3, Cell 5, Etc.,

  Imgae-2- Cell 2, Cell 4,Cell 6, Etc.,

请指导我并给我一些示例链接。

谢谢!

I want set the background image for cell. I have already set the background images for the cells in the table view. But I want to set the two images for the background images in the table view cell. I want to set the alternate cells for the background,

Like,

  Image1- Cell 1, Cell 3, Cell 5, Etc.,

  Imgae-2- Cell 2, Cell 4,Cell 6, Etc.,

Please guide me and give me some sample links.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

池木 2024-09-23 17:43:52

您可以为偶数/不均匀行设置两个不同的单元格,如下所示

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    static NSString *CellIdentifierEvenRows = @"MyCellEven";
    static NSString *CellIdentifierUnevenRows = @"MyCellUneven";
    UITableViewCell *cell;

    if (indexPath.row % 2) {
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierUnevenRows];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                           reuseIdentifier:CellIdentifierUnevenRows] autorelease];
            cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"uneven.png"] autorelease];
        }
    } else {
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierEvenRows];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                           reuseIdentifier:CellIdentifierEvenRows] autorelease];
            cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"even.png"] autorelease];
        }
    }

    return cell;
}

(但未测试)

You can setup two different cells for even/uneven rows like below

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    static NSString *CellIdentifierEvenRows = @"MyCellEven";
    static NSString *CellIdentifierUnevenRows = @"MyCellUneven";
    UITableViewCell *cell;

    if (indexPath.row % 2) {
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierUnevenRows];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                           reuseIdentifier:CellIdentifierUnevenRows] autorelease];
            cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"uneven.png"] autorelease];
        }
    } else {
        cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierEvenRows];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                           reuseIdentifier:CellIdentifierEvenRows] autorelease];
            cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"even.png"] autorelease];
        }
    }

    return cell;
}

(not tested though)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文