gpt4 book ai didi

ios - UICollectionViewCell contentView 填充

转载 作者:行者123 更新时间:2023-12-01 18:37:39 25 4
gpt4 key购买 nike

我想为 contentView 设置填充从自定义内部 UICollectionViewCell所以它比细胞本身小。
我尝试通过为 contentView 设置 anchor 来做到这一点但这个 View 似乎总是与单元格大小相等。

这是我尝试过的。

 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 中创建了另一个 View 我可以锚定上面显示的方式,但我希望有一个更清洁的解决方案。

最佳答案

您可能想尝试设置 edge contentView 的插图,但如果你采用这种方法,你应该固定 subviews到布局边距指南,而不是直接锚定。

我来自 Swift,但我想你会理解我的:

contentView.layoutMargins = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8)
someSubview.topAnchor.constraintEqualToAnchor(contentView.layoutMarginsGuide.topAnchor).isActive = true

关于ios - UICollectionViewCell contentView 填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49447632/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com