Questions tagged [uicollectionviewcell]

UICollectionViewCell is a class from UIKit framework in iOS. A UICollectionViewCell object presents the content for a single data item when that item is within the collection view’s visible bounds. Available in iOS 6.0 and later which is inherited from `NSObject->UIResponder->UIView->UICollectionReusableView->UICollectionViewCell`

Cells present the main content of a collection view. The job of a cell is to present the content for a single item from the data source object. Each cell must be an instance of the UICollectionViewCell class, which you may subclass as needed to present your content. Cell objects provide inherent support for managing their own selection and highlight state, although some custom code must be written to actually apply a highlight to a cell. A UICollectionViewCell object is a specific type of reusable view that might be used for main data items.

To configure the appearance of your cell, add the views needed to present the data item’s content as subviews to the view in the contentView property.

Resource

Questions

4470 questions
57
votes
7 answers

Getting the screen location of a cell from a UICollectionView

This isn't so much a question as an explanation of how to solve this problem. The first thing to realize is that the UICollectionView does inherit from a UIScrollView - so doing a standard lookup with a scroll view's content is the best…
Joe Jupin
  • 571
  • 1
  • 4
  • 3
56
votes
4 answers

Why on Xcode 11, UICollectionViewCell changes size as soon as you scroll (I already set size in sizeForItem AtIndexPath:)?

I have collectionview inside tableview cell and I use nib for my collection view cell (in which I use autolayout for my imageview and labels and it is on Freeform mode). I'm setting cell size in tableviewcell class which is handling the delegate…
Reza.Ab
  • 1,195
  • 1
  • 11
  • 21
56
votes
3 answers

UICollectionView update a single cell

I am attempting to update a single cell inside a UICollectionView, specifically I am just trying to update an image in that specific cell detonated by cell.imageView. [self.collectionView reloadData] is not really an option because it makes the…
55
votes
4 answers

Dynamic size UICollectionView cell

1) How can i achieve as shown in image with UICollectionView? 2) I've tried -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath method &…
55
votes
15 answers

UICollectionView only calling didSelectItemAtIndexPath if user double taps, will not call when user single taps

I have a UICollectionView which is about the size of the screen. The UICollectionViewCells that it displays are the same size as the collectionView. Each cell has a UIImage which is the size of the cell. The CollectionView has paging enabled so…
Kris Gellci
  • 9,539
  • 6
  • 40
  • 47
53
votes
4 answers

Auto Layout in UICollectionViewCell not working

I have a simple UICollectionView with cells that have a single UITextView. The UITextView is constrained to the edges of the cell, so they should stay the same size as the cell size. The problem I'm having is that for some reason these constraints…
ryanthon
  • 2,524
  • 3
  • 17
  • 18
50
votes
5 answers

How to create UICollectionViewCell programmatically

I'm trying to create UICollectionView programatically. I need to add labels inside the cells, so I Created CollectionViewCell class. This is the class: import UIKit class MyCollectionViewCell: UICollectionViewCell { override init(frame:…
s_s
  • 709
  • 1
  • 7
  • 13
49
votes
7 answers

Is force cast really bad and should always avoid it?

I started to use swiftLint and noticed one of the best practices for Swift is to avoid force cast. However I used it a lot when handling tableView, collectionView for cells : let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellID,…
49
votes
4 answers

Resize UICollectionView cells after their data has been set

My UICollectionView cells contain UILabels with multiline text. I don't know the height of the cells until the text has been set on the label. -(CGSize)collectionView:(UICollectionView *)collectionView …
Shocks
  • 808
  • 1
  • 9
  • 18
48
votes
5 answers

Subview frame is incorrect when creating UICollectionViewCell

The problem I created a UICollectionViewController with a custom UICollectionViewCell. The custom cell contains a large and rectangular UIView (named colorView) and a UILabel (named nameLabel). When the collection is first populated with its cells…
Felipe Ferri
  • 3,488
  • 2
  • 33
  • 48
48
votes
2 answers

Create UICollectionViewCell subclass with xib

I'm trying to create a UICollectionViewCell subclass with linked a xib, I have do this: I have create a new xib file and I have add a UICollectionViewCell in it, then I have create this subclass file: @interface MyCell :…
Piero
  • 9,173
  • 18
  • 90
  • 160
46
votes
9 answers

UICollectionViewCell content wrong size on first load

I have a added a UICollectionView to my UIViewController and have made a custom cell for it. I set the size of the cell using the sizeForItemAtIndexPath method and set each cell to be UIScreen.mainScreen().bounds.width/2 in both height and width. So…
myles
  • 1,681
  • 1
  • 15
  • 27
41
votes
5 answers

How can I enable/disable section headers in UICollectionView programmatically?

How can I enable/disable section headers in UICollectionView programmatically? It can be easily done easily done in Storyboard (checkbox), but how about doing it in code?
Xyand
  • 4,470
  • 4
  • 36
  • 63
36
votes
6 answers

UICollectionview Scrolling choppy when loading cells

I have a gallery in my app utilizing a UICollectionView. The cells are approximately 70,70 size. I am using ALAssets from the ALAssetLibrary in the gallery which I have stored in a list. I am using the usual pattern for populating the…
Avba
  • 14,822
  • 20
  • 92
  • 192
35
votes
5 answers

Grid layout with CollectionView in Swift

I would like to achieve this result: Searching around I found out that probably the way to do it is using UICollectionView, so no problem with that since there are many tutorials and questions on Stack Overflow. I have 3 questions: I cannot find…
Mat
  • 6,236
  • 9
  • 42
  • 55