Pages

September 25, 2013

Get the maximum available width (or height) for items in a box

I have a UIView container and some items with fixed size.
What's the maximum allowed space betweem them?


/** Returns the maximum space between items so that they could stay within a container.

 @param numItems Number of items that must stay within a given container.
 @param itemDimenions Size of single item.
 @param containerDim Size of container.
 @return Returns the dimension of the space between all items.
 @see maxNumberOfItemsWithDimension:minSpacer:inContainerOfDimension:

 */
+ (CGFloat)maxSpaceBetweenItems:(NSInteger)numItems withDimension:(CGFloat)itemDimenions inContainerOfDimension:(CGFloat)containerDim {
    return (containerDim - numItems * itemDimenions) / (numItems + 1);
}



Download the ready-for-use source file (.m) of Get the maximum available width (or height) for items in a box

No comments:

Post a Comment