I know how to use @IBDesignable with custom views. but is it possible to use IBDesignable for cells and render them in storyboard?
for example: i have a collectionViewController in storyboard, and added a uiCollectionCell and specified class as my customCellClass.
p.s: i know for using Xibs in collecionViews and tableViews we have to call method registerNib:forReuseIdentifer in code (and i am doing it). just wondered, is it possible to see it's rendered view in storyboard or not.
p.s2: i found this and it works perfectly with UIViews, but don't know how to make it work with CollectionCells and TableCells. :(
Yes. Here is what I found with Xcode 10.1 and iOS 12. Adding
@IBDesignable
to the custom subclass ofUICollectionViewCell
did work intermittently, but this works more reliably:@IBDesignable
to a custom subclass ofUIView
layoutSubviews()
, and define the appearance thereprepareForInterfaceBuilder()
UICollectionViewCell
in Interface BuilderMenu / Editor / Automatically Refresh Views
is checked, make some other change in Interface Builder)Example Class
After lots of testing and working with the library I came up with this:
you should not add
TableViewCell
orCollectionViewCells
inside.nib
files, instead you have to add simple View. I'm not sure if it's gonna show up inside storyboard or not (haven't checked it yet) but it makes errors go away. Now you can even useautoLayout
for self sizing cells.