我创建了自定义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时,它可以正常工作 但在新设备中它运行不好。在这种情况下,我不知道如何增加掩模尺寸。 我该如何修复这个错误?