0

我正在使用https://github.com/alekseyn/EasyTableView创建带有图像的可滚动表格视图。它在演示中给出的效果非常好。

但我的自定义要求是 2 行而不是 1 行。所以我决定为表格中的单个单元格添加 2 个图像视图而不是 1 个。

- (UIView *)easyTableView:(EasyTableView *)easyTableView viewForRect:(CGRect)rect {
    // Create a container view for an EasyTableView cell
    UIView *container = [[UIView alloc] initWithFrame:rect];;

    // Setup an image view to display an image
    UIImageView *imageView  = [[UIImageView alloc] initWithFrame:CGRectMake(1, 0, rect.size.width-2, rect.size.height/2)];
    imageView.tag           = IMAGE_TAG;
    imageView.contentMode   = UIViewContentModeScaleAspectFill;

    [container addSubview:imageView];

    // Setup a label to display the image title
    CGRect labelRect        = CGRectMake(10, rect.size.height/2-20, rect.size.width-20, 20);
    UILabel *label          = [[UILabel alloc] initWithFrame:labelRect];
    label.textAlignment     = UITextAlignmentCenter;
    label.textColor         = [UIColor colorWithWhite:1.0 alpha:0.5];
    label.backgroundColor   = [UIColor clearColor];
    label.font              = [UIFont boldSystemFontOfSize:14];
    label.tag               = LABEL_TAG;

    [container addSubview:label];

    // Setup an image view to display an image
    UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(1, rect.size.height/2, rect.size.width-2, rect.size.height)];
    imageView.tag           = IMAGE_TAG2;
    imageView.contentMode   = UIViewContentModeScaleAspectFill;

    [container addSubview:imageView2];

    // Setup a label to display the image title
    CGRect labelRect2       = CGRectMake(10, rect.size.height-20, rect.size.width-20, 20);
    UILabel *label2         = [[UILabel alloc] initWithFrame:labelRect2];
    label.textAlignment     = UITextAlignmentCenter;
    label.textColor         = [UIColor colorWithWhite:1.0 alpha:0.5];
    label.backgroundColor   = [UIColor clearColor];
    label.font              = [UIFont boldSystemFontOfSize:14];
    label.tag               = LABEL_TAG2;

    [container addSubview:label2];

    return container;
}

// Second delegate populates the views with data from a data source

- (void)easyTableView:(EasyTableView *)easyTableView setDataForView:(UIView *)view forIndexPath:(NSIndexPath *)indexPath {
    // Set the image title for the given index
    UILabel *label = (UILabel *)[view viewWithTag:LABEL_TAG];
    label.text = [self.imageStore.titles objectAtIndex:indexPath.row];

    // Set the image for the given index
    UIImageView *imageView = (UIImageView *)[view viewWithTag:IMAGE_TAG];
    imageView.image = [self.imageStore imageAtIndex:indexPath.row];

    // Set the image title for the given index
    UILabel *label2 = (UILabel *)[view viewWithTag:LABEL_TAG2];
    label2.text = [self.imageStore.titles objectAtIndex:indexPath.row];

    // Set the image for the given index
    UIImageView *imageView2 = (UIImageView *)[view viewWithTag:IMAGE_TAG2];
    imageView2.image = [self.imageStore imageAtIndex:indexPath.row];

}

最初为了测试,我对两个单元格使用了相同的图像和标签。但令人怀疑的是,它在第​​一行显示图像和行意味着任何单元格的第一张图像。

我怎样才能完成我的要求。

4

0 回答 0