How to set the UICollectionViewCell size
source link: https://www.codesd.com/item/how-to-set-the-uicollectionviewcell-size.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
I have using a UICollectionView
and set images in cells. I want a cell sizes is width = view/2
and hight = view/3
. and top margin =8
, right = 8
, left = 8
.I attached an image please see ones. I want to like this please see an image.
MY CODE
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return img_ary.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
category_cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
cell.img_view.image = [UIImage imageNamed:[img_ary objectAtIndex:indexPath.row]];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
// [self performSegueWithIdentifier:@"showRecipeDetails" sender:self];
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
return UIEdgeInsetsMake(0, 0, 0, 0); //top, left, bottom, right);
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
CGFloat widthOfCell =(self.view.frame.size.width-30)/2;
CGFloat heightOfCell =(self.view.frame.size.height-30)/4;
CGSize returnValue = CGSizeMake(widthOfCell, heightOfCell);
returnValue.height += 5;
returnValue.width += 5;
return returnValue;
}
IMAGE: I want to likes this please see
I tried to many times and many more methods are used but not set cell like attached image. please suggest how can I do this. Thankyou
Have you tried
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath;{
CGSize defaultSize = CGSizeMake((_collectionViewSongs.frame.size.width/2)-10, (_collectionViewSongs.frame.size.width/2)-10);
return defaultSize;
}
Recommend
-
62
THE NEXT BIG small THING™ Gluon Erlang Abstract Machine A configurable and small virtual machine whi...
-
187
Presenting a hobby project that I’ve been doing for several months now. It is named after “gluon”, a particle which acts as the exchange particle for the strong force betwe...
-
43
README.md CocoaPods Size Measurement According to
-
31
但是最近遇到一个奇葩的 UI bug,非常无奈,当时在网上查了半天也没查到,所以在这记录一下。
-
8
How To Measure the Working Set Size on Linux 17 Jan 2018
-
4
Working Set Size Estimation
-
5
Set Chart Size with ChartJS Mar 25, 2022 To set the chart size in ChartJS, we recommend using the responsive option, which makes the Chart fill its container. You must wrap the...
-
2
GORM Set size for the string field Published: Jun 8, 2020 / Last modified: Jun 8, 2020 In GORM package, you can specify field’s size using 2 options.
-
5
Reverse a Linked List in groups of given sizeSkip to content
-
10
This tutorial will discuss about the set size() function in C++ stl. Table Of Contents Advertisements The C++ set container, which is a part of the Standard Template Library (STL), is...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK