Search code examples
cocoansscrollview

How can one draw a background in the elastic portion of an NSScrollView?


I have a custom NSScrollView with elasticity turned on in both orientations. Currently I just get a black (ugly) background when I scroll/bounce into this elastic section. How do I control what gets drawn into this section?

For a start, I would just want to be able to set the background colour of this section to a specific colour.

Things I have tried that do NOT seem to work:

  1. Using the background property of the NSSCrollView - it doesn't seem to do anything which is also strange?
  2. Setting the custom NSScrollView.wantsLayer = true and then choosing an appropriate CGColor => also no effect
  3. Adding an independent subView with a background color to NSScrollView that fills it vertically and horizontally (even tried overfilling by using negative leading spaces) => no effect
  4. Trying to use constraints to make the contentView bigger than the NSScrollView => no discernible effect
  5. Making the documentView bigger => it just made the documentView extend for said amount (this was silly, but one does get desperate!)
  6. Setting the background on the NSClipView as suggested in a comment below => no effect

Solution

  • Well if at first you don't succeed (and nobody has answered your question on SO yet)...

    What worked is to add a subview to the NSClipView (not the NSScrollView) constraining it to be adjacent to the documentView where the elasticity is arising. That's all...