我正在處理一個基於從MySQL數據庫返回的數據填充5個項目的項目。我的問題是我需要根據返回的數據製作每個項目的圓形或方形。在collectionView中創建形狀cellForItemAtIndexPath - 目標C
當運行以下內容:創建一個正方形稱爲
UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
_collectionView=[[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout];
[_collectionView setDataSource:self];
[_collectionView setDelegate:self];
[_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"];
[_collectionView setBackgroundColor:[UIColor whiteColor]];
CGRect frame = [_collectionView frame];
[_collectionView setFrame:CGRectMake(10,
5,
300,
frame.size.height - 100)];
[self.view addSubview:_collectionView];
..A自定義佈局。我的問題是我怎樣才能使它在單元格創建功能內的方形或圓形?
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
.... do my creation of circle or square in here
}
,而不是在這裏:
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(50, 50);
}
能給我在哪裏打電話的例子嗎?我的意思是在我的單元格創建中,我將在哪裏查看「UICollectionViewCell」。 –
編輯我的答案 – Dima