Прозрачность между UITableViewCells - PullRequest
1 голос
/ 22 сентября 2010

Я хочу иметь прозрачность между UITableViewCells.Пространство между ячейками.

Я использую пользовательские ячейки и для задания фона я использую этот код:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CustomCell = @"CustomBookingCell";

    currentBooking = [arrayBookings objectAtIndex:indexPath.row];

    CustomBookingCell *cell = (CustomBookingCell *)[tableView dequeueReusableCellWithIdentifier:CustomCell];

    if (cell == nil) {

        UIViewController *c = [[UIViewController alloc] initWithNibName:@"CustomBookingCell" bundle:nil];
        cell = (CustomBookingCell *)c.view;
        [ c release ];
    }



    bookingImage = [[UIImageView alloc] initWithImage:
                     [UIImage imageNamed:currentBooking.imageSource]];

    [cell.imageForBooking addSubview:bookingImage];
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    cell.contentView.backgroundColor = [UIColor clearColor];


    UIView* backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
    UIImage* bgImage = [UIImage imageNamed:@"Background_300_82.png"];
    UIColor *bgColor = [[UIColor alloc] initWithPatternImage: bgImage];

    backgroundView.backgroundColor = bgColor;
    cell.backgroundView = backgroundView;
    cell.label.text = currentBooking.title;

    [bookingImage release];
    [bgColor release];
    [backgroundView release];


    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 90;
}

Высота ячейки на 10 пикселей выше, чем tableCellBg.png.Мой фоновый вид также имеет изображение в качестве фона (этот фон, конечно, должен отображаться между ячейками).

Поэтому я попытался добавить 10 пикселей с прозрачностью к моему tableCellBg.png внизу, чтобы исправить это.,Но пространство между клетками черное.Я не вижу фонового изображения между своими клетками.

Что мне делать?Нужно ли создавать UIView в cellForRowAtIndexPath с высотой tableCellBg.png, а затем добавить Custom UITableViewCell в качестве подпредставления к созданному UIView с меньшей высотой?

Или есть более простой способвыполнить это?

Ответы [ 2 ]

5 голосов
/ 22 сентября 2010

Вашему табличному виду нужен четкий цвет фона.Например

myTableView.backgroundColor = [UIColor clearColor];
1 голос
/ 25 сентября 2010

Я решил это с помощью другого метода добавления фонового изображения в UITableViewCell:

    UIImage *image = [UIImage imageNamed:@"ny_bg_event.png"];
UIImageView  *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(0, 0, 300, 84);
cell.backgroundView = imageView;
cell.backgroundColor = [UIColor clearColor];
[imageView release];

[cell setFrame:CGRectMake(0, 0, 300, 84)];

cell.contentView.backgroundColor = [UIColor clearColor];

Вместо создания UIView я просто использовал вместо него UIImageView.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...