In Xcode, if say I have a UICollectionViewCell
that has a UIImageView
in it, I am used to making a custom cell class to access that UIImage
. However, is this necessary? I am convinced that I don't have to make a custom cell class just to access a UIImage
.
Would I have to do something like...
for var subview in cell.subviews
{
if subview is UIImageView
{
subview = UIImageView()
subview.image = //change image here
}
}
Thank you!
Never dig into the private subview structure of views. That implementation can change in any iOS update. That image view you are finding is there for other purposes.
UICollectionViewCell
does not provide an image property that you can use. If you wish to show an image, create a custom cell class that contains your own UIImageView
setup with your desired constraints. Use that image view, not one you happen to find by digging into the private subviews.
Provide a property in your custom cell class to make it simple to access that image view in the cellForItemAt
method.