How to create UITableView like GRID in landscape mode?

后端 未结 1 1104
暖寄归人
暖寄归人 2020-12-22 11:12

I wanna create the uitableview like this image . loading data from server and assigning the values to columns of Row. I saw the link of stack, but not helpful t

相关标签:
1条回答
  • 2020-12-22 11:24

    Well this will require a bit more code than the method you present. My suggestion is you could create a UILabel for each of your fields, instrad of using a single NSString. Don't use cell.textLabel, but rather add your content on cell.contentView and then you can manage each label's color, background color and labels' sizes. The "grid" look can be rendred by assigning a white color to contentView and assigning a green color for example to each label's background. For example, after your cell is created :

    cell.contentView.backgroundColor = [UIColor clearColor];
    
    UILabel* aLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 0.0, 100, 44)];
    aLabel.tag = indexPath.row;
    aLabel.textAlignment = UITextAlignmentLeft;
    aLabel.textColor = [UIColor whiteColor];
    aLabel.text = @"Test";
    aLabel.backgroundColor = [UIColor greenColor];
    [cell.contentView addSubview:aLabel];
    [aLabel release];
    

    Start your next label at 201 or more to leave an impression of a white vertical line. Keep the row index in the tag so you can manage alternate colors in :

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell
                                                            *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
        if (indexPath.row == 0 || indexPath.row%2 == 0) {
            // use light green, get access to the labels via [cell.contentView viewWithTag:indexPath.row]
        } else {
            // use dark green   
        }
    }
    

    Hope this helps.

    0 讨论(0)
提交回复
热议问题