2个单元之间的边距

时间:2019-04-07 21:54:00

标签: ios objective-c

嗨,我正在尝试为我的所有PackageCell添加顶部和底部边距。 像Cells need space between eachother

我尝试过的

  %hook PackageCell
-(void)didMoveToWindow {

    self.layer.cornerRadius = 15.0f;
    self.layer.masksToBounds = true;
    %orig;
}
-(CGRect)frame {
    CGRect r = %orig;
    return CGRectMake(40, 0, r.size.width, r.origin.height+20);
}
-(void)setFrame:(CGRect)frame {
    CGRect r = frame;
      %orig(CGRectMake(40, 0, r.size.width, r.origin.height+20));
}

%end

所有单元格堆叠在一起,看起来很奇怪。

1 个答案:

答案 0 :(得分:0)

您应将单元格的backgroundColor设置为[UIColor clear]

然后改为更改contentView的框架并使该视图变成圆形

self.contentView.layer.cornerRadius = 15.0f;

并为此更新框架

self.contentView.frame = CGRectMake(40, 0, self.frame.size.width, self.frame.origin.height+20);