цвет фона uitableviewcell становится прозрачным - PullRequest
0 голосов
/ 07 августа 2011

У меня проблема с тем, что цвет фона ячейки всегда становится прозрачным.Я установил серый цвет фона uiview, прозрачный цвет фона tableview, и не установил чистый цвет фона tableviewcell.Но фон ячейки всегда выглядит серым.Может ли кто-нибудь иметь представление об этом.

Спасибо

enter image description here

-(void)viewDidLoad
{
    self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"TableBackGround.png"]];

    Acc_Details_TView.backgroundColor = [UIColor clearColor];
    Acc_Details_TView.rowHeight = 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"TransCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    switch ([Acc_Details_SegCtrl selectedSegmentIndex]) {
        case 0:{
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TableCell"] autorelease];
                cell.backgroundColor =[UIColor clearColor];
                cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
                cell.detailTextLabel.text = [[transcationsList objectAtIndex:([indexPath row])] valueForKey:@"Date"];
                cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
            }
            NSString *titleName =[[transcationsList objectAtIndex:([indexPath row])] valueForKey:@"Title"] ;
            if ([titleName length] > 19) {
                cell.textLabel.text = [titleName substringWithRange:NSMakeRange(0, 20)];                
            }
            else{
                cell.textLabel.text = titleName;
            }

            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            UILabel * acc_Amount = [[UILabel alloc] initWithFrame:CGRectMake(220, 5, 60,10)];
            acc_Amount.textAlignment = UITextAlignmentRight;
            acc_Amount.backgroundColor = [UIColor clearColor];
            acc_Amount.text = [[transcationsList objectAtIndex:([indexPath row])] valueForKey:@"Amount"];
            acc_Amount.font = [UIFont boldSystemFontOfSize:14];
            [cell.contentView addSubview:acc_Amount];
            UILabel * balance_Amount = [[UILabel alloc] initWithFrame:CGRectMake(220, 23, 60,10)];
            balance_Amount.textAlignment = UITextAlignmentRight;
            balance_Amount.text = @"$1234.50";
            balance_Amount.backgroundColor = [UIColor clearColor];
            balance_Amount.textColor = [UIColor grayColor];
            balance_Amount.font = [UIFont systemFontOfSize:12];
            [cell.contentView addSubview:balance_Amount];
            return cell;            
        }
    }
}

Ответы [ 3 ]

5 голосов
/ 07 августа 2011

Попробуйте установить цвет фона вашей ячейки в методе

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

, а не в методе cellForRowAtIndexPath:.

4 голосов
/ 07 августа 2011

Ваши клетки не совсем прозрачны. Установка UITableView backgroundColor делает некоторые безумные недокументированные вещи. Лучший способ убедиться в этом - установить полупрозрачный цвет, например [UIColor colorWithWhite:0.5 alpha:0.5], с помощью которого вы получите что-то вроде этого:

weird table view

Чтобы решить вашу проблему, вам нужно будет установить в ячейках contentView.backgroundColor и backgroundColors всех подпредставлений после установки tableView. Вот ваш cellForRowAtIndexPath: обновленный с этим:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"TransCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    UIColor *cellBackgroundColor = [UIColor whiteColor];

    switch ([Acc_Details_SegCtrl selectedSegmentIndex]) {
        case 0:{
            if (cell == nil) {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TableCell"] autorelease];
                cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
                cell.detailTextLabel.text = [[transcationsList objectAtIndex:([indexPath row])] valueForKey:@"Date"];
                cell.detailTextLabel.font = [UIFont systemFontOfSize:12];
                cell.accessoryView.backgroundColor = cellBackgroundColor;
                cell.backgroundView.backgroundColor = cellBackgroundColor;
                cell.contentView.backgroundColor = cellBackgroundColor;
                cell.textLabel.backgroundColor = cellBackgroundColor;
                cell.detailTextLabel.backgroundColor = cellBackgroundColor;
                UIView *backView = [[UIView alloc] initWithFrame:cell.frame];
                backView.backgroundColor = cellBackgroundColor;
                cell.backgroundView = backView;
                [backView release];
            }
            NSString *titleName =[[transcationsList objectAtIndex:([indexPath row])] valueForKey:@"Title"] ;
            if ([titleName length] > 19) {
                cell.textLabel.text = [titleName substringWithRange:NSMakeRange(0, 20)];                
            }
            else{
                cell.textLabel.text = titleName;
            }

            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            UILabel * acc_Amount = [[UILabel alloc] initWithFrame:CGRectMake(220, 5, 60,10)];
            acc_Amount.textAlignment = UITextAlignmentRight;
            acc_Amount.backgroundColor = cellBackgroundColor;
            acc_Amount.text = [[transcationsList objectAtIndex:([indexPath row])] valueForKey:@"Amount"];
            acc_Amount.font = [UIFont boldSystemFontOfSize:14];
            [cell.contentView addSubview:acc_Amount];
            UILabel * balance_Amount = [[UILabel alloc] initWithFrame:CGRectMake(220, 23, 60,10)];
            balance_Amount.textAlignment = UITextAlignmentRight;
            balance_Amount.text = @"$1234.50";
            balance_Amount.backgroundColor = cellBackgroundColor];
            balance_Amount.textColor = [UIColor grayColor];
            balance_Amount.font = [UIFont systemFontOfSize:12];
            [cell.contentView addSubview:balance_Amount];
        }
    }
    return cell;
}
0 голосов
/ 07 августа 2011

Я не понял вашего вопроса.Вы установили серый фон стола, затем очистили, но не сделали его прозрачным, а затем он выглядит серым, что вам не нужно, даже если вы установите его серым?

table.backgroundColor = [UIColor clearColor];
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...