![](/img/trans.png)
[英]Resizing a UICollectionView with layout constraints. Section headers move
[英]UicollectionView with layout constraints
我在視圖控制器中使用集合視圖。
我沒有在IB中使用自動布局,而是在調整集合視圖的大小。
我的問題是在iphone 4s中正常工作。 當我在iPhone 6上運行時不正確。
我可以使用nslayout約束嗎? 我的imageview單元格大小寬度80和高度90是固定的。
有什么解決方案可以使所有設備工作?
您可以自動調整集合視圖的大小,該視圖將適用於除iPhone 4s以外的所有iPhone設備,因此對於iPhone 4S,您可以通過編程設置其對齊方式。 如
-(void)ViewDidLoad{
//get the screen size of device
screenHeight = [UIScreen mainScreen].bounds.size.height;
if (screenHeight == 480){
//Your code e.g
<collectionView>.frame = CGRectMake((x-axis),(y-axis),width,height);
}
}
如果您不使用自動布局,請通過屬性設置自動調整大小的蒙版
您也可以通過代碼進行操作:
view.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleLeftMargin);
如果要按設備更改收集視圖的單元格大小,請使用以下方法:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake((collectionView.frame.size.width/4)-5, (collectionView.frame.size.width/4)-5);
}
這里5是您在單元格之間的填充。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.