简体   繁体   English

设置uicollectionView单元的比例大小?

[英]set propotional size for uicollectionView cell?

Helo all, 大家好,

I have create a UIcollectionView cell.I want set the height & width propotional to all devices.For eg.If height 80 & width is 90 on iphone 5s then it should be propotional on other devices as well.I am using this method. 我已经创建了一个UIcollectionView单元格。我想为所有设备设置高度和宽度比例。例如,如果在iPhone 5s上,高度和宽度为90,那么它在其他设备上也应该比例。我正在使用这种方法。

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{

    return CGSizeMake(80, 90);
}

Try using this 试试这个

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake(self.view.frame.size.width/.25, self.view.frame.size.width/.28);
}

All you have to do is multiply the dimensions of your cell by whatever proportion you desire. 您所要做的就是将单元的尺寸乘以所需的比例。 If 80x90 is the size you want on the iPhone 5, then calculate the appropriate multipliers by consulting a guide like this one . 如果您要在iPhone 5上使用80x90的尺寸,请咨询像这样的指南来计算适当的倍数。 For example, the 5's point resolution is 320 x 568, and the 6's is 375 x 667, so your width multiplier will be 375/320, and the height one will be 667/568. 例如,5的点分辨率为320 x 568,而6的点分辨率为375 x 667,因此您的宽度乘数将为375/320,而高度的乘数将为667/568。 (I'll let you do the math. :)) (我让你算一下。:)

use this 用这个

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
return CGSizeMake(self.view.frame.size.width/2, self.view.frame.size.width/2);
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
return 0
;}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
return 0; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM