gpt4 book ai didi

ios - UICollectionView 单元格框架具有十进制原始值

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:41:40 25 4
gpt4 key购买 nike

我有一个以编程方式创建的 UICollectionView。 Collection View 中的每个单元格都显示一个标签,所有标签都具有相同的属性。尽管如此,我注意到 Collection View 中心列中每个标签中包含的文本看起来很模糊。

Collection View 的递归描述显示表格中的中心单元格始终具有一个十进制值的 x 原点:

 <UICollectionViewCell: 0xd98c1e0; frame = (242.5 0; 220 45); layer = <CALayer: 0xd98c270>> ...

我的问题是:1) 这会导致模糊吗?和 2) 确保 x 和 y 原点最终都没有十进制值的最佳方法是什么? (除了手动计算布局)

作为引用,这是我的 UICollectionView 代码:

//subclass UICollectionViewFlowLayout

@implementation LabelLayout

-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds{
return YES;
}

- (id)init
{
self = [super init];
if (self) {
[self setup];
}
return self;
}

-(void)prepareLayout
{
[super prepareLayout];
_cellCount = [[self collectionView] numberOfItemsInSection:0];
}

- (void)setup
{
self.itemSize = CGSizeMake(220.0f, 45.0f);
self.sectionInset = UIEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f);
self.minimumLineSpacing = 10.0f;
self.minimumInteritemSpacing = 20.0f;
}

@end

最佳答案

这肯定会导致模糊,因为所有内容都在两个像素上消除锯齿(注意:在视网膜屏幕上,您不会看到任何模糊,因为每个点实际上是两个像素,所以半点在技术上作为单个像素存在) .要修复它,您可能必须使用 CGRectIntegral 将框架强制为整数边界。最好的方法是:

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect{
NSArray *attributes = [super layoutAttributesForElementsInRect:rect];
for (NSLayoutAttributes *attribute in attributes){
attribute.frame = CGRectIntegral(attribute.frame);
}
}

您应该为 layoutAttributesForItemAtIndexPath: 做同样的事情。

关于ios - UICollectionView 单元格框架具有十进制原始值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17957742/

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