0
votes

I have hit a slight problem with UICollectionViews. I have posted a question before here but I think I have moved bit -

UICollectionView - Autolayout with pinterest style layout

Objective -

UICollectionview with a custom positional layout with the cells using auto layout.

Current state of play:

I currently have a LayoutView which inherits from UICollectionViewLayout. In my PrepareLayout() I am looping around my collection of items and create a list of attributes which I then return via the LayoutAttributesForElementsInRect depending on the rectangle.

Also during the PrepareLayout I use "prototype" cells (cells that are used only to get the correct size and not part of the UI). I populate the cells with the data and then ask the cell for the minimal height. The width is calculated based on how wide my current item needs to be - i.e. if it spans a number of columns.

Issue:

So my problem that I have hit is that my cells consist of multiple labels that are multiline (0 lines). I have created constraints attached to the ContentView top, left, right and bottom but I can't seem to get the label to wrap correctly. I know that UILabel requires the PreferedMaxWidth to be set but my problem is that my cell is going to have a UIImageView beside the label so I don't think I can calculated the available space that remains.

Could anyone lend a helping hand or point me in the general direction of where to find some more information?

1
Have you ever gone through the "Pinterest Style Layout Tutorial" on Ray Wenderlich's site? raywenderlich.com/164608/… - DonMag
Yeah, apologises I probably should have state that - I have that was my original starting point but unfortunately it is the auto layout side of things that appears to be causing me the issues. - Robert
hmmm... it's been quite a while since I looked at that, but I thought it was using auto-layout? - DonMag
hmm... maybe i am missing something really obvious then. I will double check. - Robert
Just checked... I guess it's using auto-layout for the positioning, but it's calculating the height with NSString boundingRect with size... is that not sufficient? - DonMag

1 Answers

0
votes

AFAIK, there is no way to auto-layout the UICollectionViewCell purely, check out the CHTCollectionViewWaterfallLayout instead.