1

我创建了自定义表格视图单元格

@implementation AccountNewsCell
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor clearColor]];
        CustomColoredAccessory *accessory = [CustomColoredAccessory accessoryWithColor:[UIColor colorWithRed:157.0/255.0 green:145.0/255.0 blue:196.0/255.0 alpha:1.0]];
        self.accessoryView =accessory;

        UIView * backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.viewForBaselineLayout.bounds.size.width, 44)];
        [backgroundView setBackgroundColor:[UIColor whiteColor]];
        backgroundView.alpha=0.6;
        [self setBackgroundView:[self viewWithMask:backgroundView]];
    }
    return self;
}


-(UIView *) viewWithMask:(UIView *)view
{
    UIBezierPath* roundedRectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(7, 1, view.frame.size.width-14, 40) cornerRadius: 5];
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = roundedRectanglePath.CGPath;
    [view.layer setMask:shapeLayer];
    view.translatesAutoresizingMaskIntoConstraints = YES;
    return view;

}

创建tableview单元格的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

        static NSString *CellIdentifier = @"news";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        cell.backgroundView=[[AccountNewsCell alloc] init];
        UIView * selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
        [selectedBackgroundView setBackgroundColor:[UIColor whiteColor]];
        cell.selectedBackgroundView=[self viewWithMask:selectedBackgroundView];
        return cell;
}

在屏幕宽度为 320pt 的 iphone 4、5、5s 中,它工作正常 在此处输入图像描述 ,但在新设备中,它工作得不好。我不知道在这种情况下如何增加蒙版尺寸。 在此处输入图像描述 在此处输入图像描述 我怎样才能修复这个错误?

4

0 回答 0