Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>[self _layoutViews:self.imageViews inView:self.view]; - (void) _layoutViews:(NSArray *)views inView:(UIView *)contentView { NSInteger overallWidth = 0; for ( UIView *view in views ) { overallWidth += view.frame.size.width; } CGSize contentSize = contentView.frame.size; CGFloat startOffset = (contentSize.width - overallWidth)/2.0; CGFloat offset = startOffset; for ( UIView *view in views ) { CGRect frame = view.frame; frame.origin.x = offset; frame.origin.y = (contentSize.height/2.0) - (frame.size.height/2.0); view.frame = frame; offset += view.frame.size.width; } } </code></pre> <p>For your example code it would be something like this:</p> <pre><code> CGFloat count = [_lettersArray count]; NSMutableArray *imageViews = [[NSMutableArray alloc] initWithCapacity:count]; for (int i = 0; i &lt; [_lettersArray count]; i++) { UIImage *imageContainer = [UIImage imageNamed:@"container.png"]; UIImageView *containerView = [[UIImageView alloc] initWithImage:imageContainer]; containerView.frame = CGRectMake(0,120,imageContainer.size.width,imageContainer.size.height); [imageViews addObject:containerView]; [self.view addSubview:containerView]; } [self _horizontalCenterViews:imageViews inView:self.view]; return YES; } - (void) _horizontalCenterViews:(NSArray *)views inView:(UIView *)contentView { NSInteger overallWidth = 0; for ( UIView *view in views ) { overallWidth += view.frame.size.width; } CGSize contentSize = contentView.frame.size; CGFloat startOffset = (contentSize.width - overallWidth)/2.0; CGFloat offset = startOffset; for ( UIView *view in views ) { CGRect frame = view.frame; frame.origin.x = offset; view.frame = frame; offset += view.frame.size.width; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload