ios - UICollectionViewCell dynamic height depending on UITextView font lineHeight -
i trying implement collection view cells having dynamic height.
some of collection view cells contains uitextview, uitextviews have height configured :
[textviewheightconstraint setconstant: numberofrowstodisplay * [[textview font] lineheight]]; the textview subview of view in specific .xib, xib view added subview of cell when cell dequeued (when collectionview:cellforitematindexpath: called).
but need return height of cell in "collectionview:sizeforitematindexpath:" method cell instance not accessible, cannot access textview : [[textview font] lineheight] property.
how can solve ?
ps : textview empty, height not dependent of nsstring on can call sizewithfont: method, , cannot hard code textview height. "numberofrowstodisplay" retrieved @ runtime, , textview font not hardcoded too.
edit : tried call "dequeuereusablecellwithreuseidentifier:forindexpath:" in "collectionview:sizeforitematindexpath:" method, creates infinite loop, if calling "collectionview:cellforitematindexpath:".
you need set view controller delegate flow layout class.
see here: uicollectionviewdelegateflowlayout protocol reference
Comments
Post a Comment