1
我是iOS和Xamarin的新手。我創建了CollectionView
,其中主框架的全部爲Width
和Height
。現在我想要使用150
Height
和完整Width
將收集視圖大小更改爲父母Horizontal Scroll
。我嘗試更改代碼,但它不起作用。如何更改iOS中collectionView的大小
的CollectionView全屏:
UICollectionViewDataSource source;
UICollectionViewFlowLayout layout;
UICollectionView collectionView;
protected ViewController(IntPtr handle) : base(handle)
{
layout = new UICollectionViewFlowLayout
{
SectionInset = new UIEdgeInsets(20, 5, 5, 5),
MinimumInteritemSpacing = 5,
MinimumLineSpacing = 5,
ItemSize = new SizeF(100, 100),
};
collectionView = new UICollectionView(UIScreen.MainScreen.Bounds, layout);
collectionView.ContentSize = new CGSize(View.Frame.Size.Width, View.Frame.Size.Height);
collectionView.BackgroundColor = UIColor.White;
source = new UICollectionViewDataSource();
collectionView.RegisterClassForCell(typeof(TextCell), TextCell.CellId);
collectionView.Source = source;
}
輸出:
我預計:
寬度=父寬度,
高度= 150
所以我更改代碼以這種
layout = new UICollectionViewFlowLayout
{
SectionInset = new UIEdgeInsets(20, 5, 5, 5),
MinimumInteritemSpacing = 5,
MinimumLineSpacing = 5,
ItemSize = new SizeF(100, 100),
};
collectionView = new UICollectionView(UIScreen.MainScreen.Bounds, layout);
collectionView.ContentSize = new CGSize(View.Frame.Size.Width, 150);
collectionView.BackgroundColor = UIColor.White;
source = new UICollectionViewDataSource();
collectionView.RegisterClassForCell(typeof(TextCell), TextCell.CellId);
collectionView.Source = source;
而且它在全屏幕中顯示。
任何幫助被讚賞。