Reputation: 2865
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:
NSScrollView.wantsLayer = true
and then choosing an appropriate CGColor
=> also no effectNSScrollView
that fills it vertically and horizontally (even tried overfilling by using negative leading spaces) => no effectNSClipView
as suggested in a comment below => no effectUpvotes: 2
Views: 488
Reputation: 1582
This answer applies if you have a custom NSView
assigned as your documentView
.
As of the macOS 14 SDK, assuming you haven't overridden clipsToBounds
(which now defaults to NO
), drawRect
will be called with a dirty rectangle that may exceed the bounds of the view, which allows you to draw the overhang that appears during elastic scrolling.
In prior versions of the SDK, it is necessary to instead define a drawBackgroundOverhangInRect
method in your NSView
subclass to do this drawing instead. In this case, clipsToBounds
must be kept at the default value of YES
, or this method will not be called (in my experience).
Upvotes: 0
Reputation: 2865
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...
Upvotes: 3
Reputation: 4728
Add a subview to the scrollView which is not the documentView, and this view will not scroll or magnify. Constrain that view to the edges so that it is the full size of the scrollView
Upvotes: 2