如何调整iPhone 6和iPhone 6Plus设备的自定义tableview单元格中的图层蒙版

时间:2014-09-23 03:48:22

标签: ios objective-c uitableview calayer iphone-6

我创建了自定义tableview单元格

@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;
}

在iphone 4,5,5s中,当屏幕宽度为320pt时,它可以正常工作 enter image description here 但在新设备中它运行不好。在这种情况下,我不知道如何增加掩模尺寸。 enter image description here enter image description here 我该如何修复这个错误?

0 个答案:

没有答案