Skip to content

Instantly share code, notes, and snippets.

@robinhayward
Created November 21, 2012 15:31
Show Gist options
  • Save robinhayward/4125463 to your computer and use it in GitHub Desktop.
Save robinhayward/4125463 to your computer and use it in GitHub Desktop.
Evenly spacing items from their center
- (void)midPointsForContainerWidth:(CGFloat)containerWidth itemWidth:(CGFloat)itemWidth itemCount:(NSInteger)itemCount
{
CGFloat itemSpace = (containerWidth - (itemCount * itemWidth)) / (itemCount + 1);
for (int i = 0; i < itemCount; i++) {
CGFloat point = itemSpace + ((itemWidth / 2));
if (i > 0) {
point += (itemWidth * i);
point += (itemSpace * i);
}
DLog(@"Point %f",point);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment