UITableviewCell Нижний левый и правый радиус - PullRequest
0 голосов
/ 13 июня 2018

Я применил нижний левый и правый угловой радиус к своему UITableViewCell, и он работает нормально, но ширина этого cell уменьшена. У меня есть ограничения, примененные к containerView этого cell.В чем причина этого?

enter image description here

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    RateChartTableViewCell *cell1 = (RateChartTableViewCell *)cell;

    if(indexPath.section == 0 && indexPath.row == 4)
    {
        [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
        UIBezierPath *maskPath = [UIBezierPath 
    bezierPathWithRoundedRect:cell1.containerView.bounds byRoundingCorners:( UIRectCornerBottomLeft | UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)];
        CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
        maskLayer.frame = tableView.bounds;
        maskLayer.path  = maskPath.CGPath;
        cell1.containerView.layer.mask = maskLayer;
        cell1.containerView.clipsToBounds = YES;
    }
}

Ответы [ 2 ]

0 голосов
/ 13 июня 2018

maskLayer.frame = tableView.bounds;возможно не так.Вы можете изменить его: maskLayer.frame = cell1.bounds;Надеюсь, это поможет вам.

0 голосов
/ 13 июня 2018

Это потому, что размер ячейки изменился, но maskLayer все еще сохраняет старый размер.На мой взгляд, чтобы исправить это, каждый раз, когда размер ячейки изменяется, удаляют и снова добавляют maskLayer.

RateChartTableViewCell

@interface RateChartTableViewCell : UITableViewCell

@property(nonatomic, strong) CAShapeLayer* maskLayer;
... other properties

@end

@implementation RateChartTableViewCell

- (void)configureBorders {
  UIBezierPath* maskPath =
  [UIBezierPath bezierPathWithRoundedRect:self.bounds
                        byRoundingCorners:(UIRectCornerBottomLeft |
                                           UIRectCornerBottomRight)
                              cornerRadii:CGSizeMake(10.0, 10.0)];
  _maskLayer = [[CAShapeLayer alloc] init];
  _maskLayer.frame = self.bounds;
  _maskLayer.path = maskPath.CGPath;
  self.layer.mask = _maskLayer;
  self.clipsToBounds = YES;
  self.backgroundColor = UIColor.redColor;
}

- (void)layoutSubviews {
  [super layoutSubviews];

  [_maskLayer removeFromSuperlayer];
  [self configureBorders];
}

- (void)prepareForReuse {
  [super prepareForReuse];

  [_maskLayer removeFromSuperlayer];
}

@end

ViewController

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  RateChartTableViewCell* cell = // Initialize cell

  // Do other things

  if (indexPath.section == 0 && indexPath.row == 4) {
    [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone]; // You can move this line to |viewDidLoad|
    [cell configureBorders];
  }

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