Search code examples
objective-ctableview

Objective C, make some corner - rounded, not work correctly


I want to create an item in the table view with topRight, bottomRight, bottomLeft - rounded and topLeft leave not rounded. Like this: enter image description here

i have added a "rounded code" to my method

    - (UITableViewCell *)tableView:(UITableView *)tableView
             cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
 UITableViewCell* cell = [super tableView:tableView
                       cellForRowAtIndexPath:indexPath];
                GOShadowContainerTableViewCell* commentCell = (GOShadowContainerTableViewCell*) cell; // my base class for cell
    
    // make rounded
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:commentCell.view1.bounds
                                                       byRoundingCorners:UIRectCornerBottomLeft| UIRectCornerTopRight | UIRectCornerTopLeft
                                                             cornerRadii:CGSizeMake(8.0, 8.0)];
    
        // Create the shape layer and set its path
        CAShapeLayer *maskLayer = [CAShapeLayer layer];
        maskLayer.frame = commentCell.view1.bounds;
        maskLayer.path = maskPath.CGPath;
        commentCell.view1.layer.masksToBounds = YES;
    
        // Set the newly created shape layer as the mask for the image view's layer
        view.layer.mask = maskLayer;
    
    
    }

My UI cell hierarchy

enter image description here

My problem: when i first load a view, i have list like this:

enter image description here

then i scoll down then scroll up, and everething is looks like good

enter image description here

Why it works "strange"? Please help to me to figure out why it doesnt work correctly from first time load tableview


Solution

  • what about this..

    round the standard backing layer of the Cells View and tell the layer on which corners to apply the rounded mask.

    cell.layer.cornerRadius = 5.0;
    // kCALayerMinXMinYCorner should be the upper left corner, so not used..
    cell.layer.maskedCorners = kCALayerMaxXMinYCorner | kCALayerMinXMaxYCorner | kCALayerMaxXMaxYCorner;
    

    did not check .. but looks nice or?