gpt4 book ai didi

ios - 更改 UICollectionViewCell 中的标签位置

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:44:29 26 4
gpt4 key购买 nike

我们有一个 UICollectionView,它在 Storyboard 上有一个原型(prototype)单元格。该单元格中有一个 UILabel(“label”),它在没有自动布局的情况下定位。

我们在 -collectionView:cellForItemAtIndexPath: 中使用 setFrame 有条件地设置标签的框架,如下所示:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CategoryCell *cell;
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Category" forIndexPath:indexPath];

...

if (self.isViewTypeList) {
[((CategoryCell *)cell).label setFrame:FRAME_RECT];
}

...

return cell;
}

我们已经检查过它,似乎首先它调用标签的 -setFrame: 当它到达出队时使用 Storyboard 值,然后是我们的代码,这设置了新的帧正确。除了这些没有其他调用,但标签仍保留在屏幕上的原始位置。

怎么了?为什么新框架设置不正确?是不是有其他东西超过了它?我是否必须以某种方式重新布局或刷新它?

最佳答案

取消选中 xib 中的自动布局。这可能有助于改变框架。

关于ios - 更改 UICollectionViewCell 中的标签位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20686778/

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