Ios 如何调整iPhone 6和iPhone 6Plus设备的自定义tableview单元格内的层掩码大小
我创建了自定义tableview单元格Ios 如何调整iPhone 6和iPhone 6Plus设备的自定义tableview单元格内的层掩码大小,ios,objective-c,uitableview,calayer,iphone-6,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 = [Custo
@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;
}
在iPhone4、5、5s中,当屏幕宽度为320pt时,工作正常
但在新设备中,效果很差。我不知道在这种情况下如何增加遮罩尺寸。
如何修复此错误?我通过读取单元格内的屏幕大小
-initWithFrame
函数CGSize结果=[[UIScreen mainScreen]bounds]找到了解决方案;结果=CGSizeMake(result.width、result.height);UIView*backgroundView=[[UIView alloc]initWithFrame:CGRectMake(0,0,result.width,44)]
。可能存在另一种解决方案吗?