【发布时间】:2018-09-02 00:15:31
【问题描述】:
我想从自定义UICollectionViewCell 内部为contentView 设置填充,使其小于单元格本身。
我尝试通过为contentView 设置锚点来做到这一点,但这个视图似乎总是与单元格大小相同。
这是我尝试过的。
self.contentView.translatesAutoresizingMaskIntoConstraints = false;
[self.contentView.topAnchor constraintEqualToAnchor:self.topAnchor constant:5].active = true;
[self.contentView.leftAnchor constraintEqualToAnchor:self.leftAnchor constant:5].active = true;
[self.contentView.rightAnchor constraintEqualToAnchor:self.rightAnchor constant:-5].active = true;
[self.contentView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor constant:-5].active = true;
为了快速解决问题,我在contentView 中创建了另一个视图,我可以按照上面显示的方式锚定,但我希望有一个更清洁的解决方案。
【问题讨论】:
-
在
contentView中添加一个视图并为该视图添加约束而不是contentView
标签: ios objective-c uicollectionview uicollectionviewcell padding