title: UIScrollView - Moving view to front, but below scroll indicators
body: <p>I am working with a custom view which inherits from UIScrollView. The problem I am having is adding a UILabel that should be displayed at the 'top', in front of the other views. It works, but unfortunately it also covers up the scroll indicators.</p>
  
  <p><img src="https://i.stack.imgur.com/vmD04.png" alt="enter image description here"></p>
  
  <p>As you can see, the scroll indicator is being obscured. I don't want to disable scroll indicators.</p>
  
  <p>I am adding the views directly to the UIScrollView:</p>
  
  <pre><code>UILabel *subsection = [[UILabel alloc] initWithFrame:CGRectMake(0, y * h, 
      [self totalContentWidth], [tableViewDelegate rowHeight])];
  [subsection setText:subsectionName];
  [subsection setTextAlignment:NSTextAlignmentCenter];
  
  [subSectionRows setValue:subsection forKey:key];
  
  [self addSubview:subsection];
  </code></pre>
  
  <p>and then bringing them to the front, which </p>
  
  <pre><code>- (void) bringSubsectionsToFront {   
      for (UIView* row in [self.subSectionRows allValues]) {
          [self bringSubviewToFront:row];
      }
  }
  </code></pre>
  
  <p>This behavior is confusing to me. If I peek at <code>UIView.layer.zPosition</code> of all the UIScrollView's subviews, they are all the same. </p>
  
  <p>If I adjust the <code>bringSubsectionsToFront</code> method to instead move the labels in front of the view that contains the grid lines, the behavior is the same.</p>
  
  <p>Looking at some internal view classes whose behavior works, it looks as if they are being added to the scroll view with: <code>[self insertSubview:cell atIndex:0];</code> </p>
  
  <p>What am I missing here?</p>
  
  <p><strong>Solution:</strong>
  verec remarked that I could find the bars if I really wanted to. So I iterated over the subview list at a suitable point, and sure enough, there they were. The order of the objects was as follows:</p>
  
  <pre><code>CustomCell
  ...
  UIImageView
  UIImageView
  CustomBorderView
  UILabel
  UILabel
  </code></pre>
  
  <p>Assuming this is the z ordering, no wonder my labels were always on top.</p>
  
  <p>Solution becomes simple; add UILabel's after CustomCells. This solution only works because the custom table adds CustomCells at index 0, which I believe makes scroll indicators appear after the CustomCells. If this assumption holds, I can reorder the other views relative to the CustomCells, achieving the layering effect I want.</p>