开发者

iPhone UIGroupTableView - How to hide cell border but keep section rounded border

When I am setting the

tableVie开发者_运维问答w.separatorColor = [UIColor clearColor]

its hides the section border too. Any idea, how can I hide all cell separator border, but the rounded border of the whole section should be there.

I have tried this, it works somehow, but do not refresh, even I call [cell setNeedsDisplay]. If I scroll then the contents redrawn.

UIView *bgView = [[UIView alloc] initWithFrame: CGRectMake(cell.frame.origin.x +10, -1, 
                                                                   cell.frame.size.width - 20, 
                                                                   cell.frame.size.height + 1)];
        bgView.backgroundColor = [UIColor whiteColor];
        [cell addSubview: bgView];
        [cell sendSubviewToBack:bgView];
        cell.clipsToBounds = NO;
        [bgView release];
        [cell setNeedsDisplay];


Try with using the separatorStyle property of UITableView.

@property(nonatomic) UITableViewCellSeparatorStyle separatorStyle

The possible type would be

 UITableViewCellSeparatorStyleNone,
   UITableViewCellSeparatorStyleSingleLine,
   UITableViewCellSeparatorStyleSingleLineEtched


Since I had only one cell, draw my variable number of cell as UILabel in one cell. That solve the problem for now!

// Create a cell with dynamic number of elements looking like UITableViewCellStyleValue2
- (UITableViewCell *) createDynamicCell {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell;
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                                   reuseIdentifier:CellIdentifier];
    cell.clipsToBounds = NO;

    // change frame of one or more labels
    CGRect cellFrame = self.tableView.frame;
    CGFloat startY = 5.0, startX = 10.0, extra1 = 20.0, gap = 10.0, startX2 = 0.0;

    UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(startX + 5, startY, 300 - startX * 2, 44)];
    if (costBreakupStyle == CostBreakupDepartment) {
        headerLabel.text = NSLocalizedString(@"Cost per department:", @"");
    } else {
        headerLabel.text = NSLocalizedString(@"Amount spent per airline:", @"");
    }
    headerLabel.font = [UIFont boldSystemFontOfSize:17];
    [cell addSubview:headerLabel];
    [headerLabel release];

    startY = startY + 44 + 10;  
    float mid = (cellFrame.size.width - startX * 2 ) / 2;   
    startX2 = startX + extra1 + mid + gap;

    for (int i = 0; i < [dataSource count]; i++ ) {
        startY += 5; // cell gap
        NSString *text = [dataSource objectAtIndex:i];
        UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(startX, startY, 
                                                                       mid + extra1, kThinnerRowHeight)];
        textLabel.text = [NSString stringWithFormat:@"%@:", text];

        float cost = [(NSNumber *) [costArray objectAtIndex:i] floatValue];
        NSString *detailText = [NSString stringWithFormat:@"%@ %.2f", 
                                [[Settings getInstance] getCurrencyCode], cost];
        UILabel *detailTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(startX2, startY, 
                                                                             mid - extra1 - gap, kThinnerRowHeight)];       
        detailTextLabel.text = detailText;

        textLabel.font = [UIFont systemFontOfSize:15.0];
        textLabel.textAlignment = UITextAlignmentRight;
        detailTextLabel.font = [UIFont systemFontOfSize:15.0];
        detailTextLabel.textAlignment = UITextAlignmentLeft;
        detailTextLabel.textColor = [UIColor blueColor];

        [cell addSubview:textLabel];
        [cell addSubview:detailTextLabel];
        [textLabel release];
        [detailTextLabel release];

        startY += kThinnerRowHeight;
    }

    // Total amount label
    startY += 15; // add a gap  
    NSString *text = NSLocalizedString(@"Total amount spent:", @"");
    UILabel *textLabel = [[UILabel alloc] initWithFrame:CGRectMake(startX, startY, 
                                                                   mid + 20, kThinnerRowHeight)];       
    textLabel.text = text;

    UILabel *detailTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(startX2, startY, 
                                                                         mid - extra1 - gap, kThinnerRowHeight)];
    detailTextLabel.text = [NSString stringWithFormat:@"%@ %.2f",
                            [[Settings getInstance] getCurrencyCode],
                            [[RequestResources getInstance] totalCredit]];
    textLabel.font = [UIFont systemFontOfSize:15.0];
    textLabel.textAlignment = UITextAlignmentRight;
    detailTextLabel.font = [UIFont systemFontOfSize:15.0];
    detailTextLabel.textAlignment = UITextAlignmentLeft;
    detailTextLabel.textColor = [UIColor blueColor];
    [cell addSubview:textLabel];
    [cell addSubview:detailTextLabel];
    [textLabel release];
    [detailTextLabel release];

    // Credit remaining label
    startY += kThinnerRowHeight;    
    text = NSLocalizedString(@"Total credit remaining:", @"");
    textLabel = [[UILabel alloc] initWithFrame:CGRectMake(startX, startY, 
                                                          mid + 20, kThinnerRowHeight)];        
    textLabel.text = text;  

    detailTextLabel = [[UILabel alloc] initWithFrame:CGRectMake(startX2, startY, 
                                                                mid - extra1 - gap, kThinnerRowHeight)];
    detailTextLabel.text = [NSString stringWithFormat:@"%@ %.2f",
                            [[Settings getInstance] getCurrencyCode],
                            [[RequestResources getInstance] remainingCredit]];
    textLabel.font = [UIFont systemFontOfSize:15.0];
    textLabel.textAlignment = UITextAlignmentRight;
    detailTextLabel.font = [UIFont systemFontOfSize:15.0];
    detailTextLabel.textAlignment = UITextAlignmentLeft;
    detailTextLabel.textColor = [UIColor blueColor];
    [cell addSubview:textLabel];
    [cell addSubview:detailTextLabel];
    [textLabel release];
    [detailTextLabel release];

    cellHeight = startY + kThinnerRowHeight + 10;   
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜