ios - Dynamic Height for UICollectionView Cell -


enter image description here first attempt @ creating collectionview programmatically. used couple tutorials facebook/linkedin-esque layout textview , imageview. great when there image have no idea how make cell dynamically smaller in height when there no image. know have fixed height of 500 being first attempt, not sure how set dynamically adjust.

i've seen lot of obj-c examples nothing (that can understand) swift know how implement.

func collectionview(collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, sizeforitematindexpath indexpath: nsindexpath) -> cgsize {          if let textcontent = datasource.posts[indexpath.item].textcontent {             let rect = nsstring(string: textcontent).boundingrectwithsize(cgsizemake(view.frame.width, 1000), options: nsstringdrawingoptions.usesfontleading.union(nsstringdrawingoptions.useslinefragmentorigin), attributes: [nsfontattributename:uifont.systemfontofsize(14)], context: nil)              return cgsizemake(view.frame.width, rect.height + 370)         }          return cgsizemake(view.frame.width, 500)     } } 

my vertical visual layout constraints (created extension):

 addcontstraintswithformat("v:|-8-[v0(44)]-4-[v1]-4-[v2][v3(44)][v4(1)][v5(44)]|", views: profileimg, posttextview, postimageview, likescommentslabel, dividerlineview, likebutton) 

sizeforitematindexpath 1 of collection view delegate function in can set height of each cell. in delegate add condition.. can check if cell has image or not , based on set height using cgsizemake


Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -