Hi Everyone,
I am relatively new to the forums. So please be kind 🙂 I have currently posted on Stackoverflow regarding a couple of issues I am having but I thought I might have better luck posting here as well.
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 compressed height. The width is calculated based on how wide my current item needs to be - i.e. my layout has columns and an item spans columns so widthOfOneColumn * columns span - give me the cell width.
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.
So I am currently I am setting the Cell.Frame to be the calculated width and Max nfloat value and ask for the cells compressed height. This fixes the issue but the autolayout is now throwing a warning to say
"This NSLayoutConstraint is being configured with a constant that exceeds internal limits. A smaller value will be substituted, but this problem should be fixed. Break on BOOL _NSLayoutConstraintNumberExceedsLimit() to debug. This will be logged only once. This may break in the future."
Current Constraints:
ImageView TopAnchor = ContentView TopAnchor + 23
ImageView LeftAnchor = ContentView LeftAnchor + 10
ImageView WidthAnchor = 38
ImageView Height = 38
FirstLabel - TopAnchor = ContentView TopAnchor + 23
FirstLabel - LeftAnchor = ImageView Right + 10
FirstLabel - RightAnchor = ContentView RightAnchor -10
SecondLabel - TopAnchor = FirstLabel BottomAnchor + 8
SecondLabel - LeftAnchor = FirstLabel - LeftAnchor
SecondLabel - RightAnchor = ContentView RightAnchor -10
SecondLabel - BottomAnchor = ContentView BottomAnchor -10
So im not sure how I can proceed with this.. Any help would be greatly appricated.