-1

I am new to macOS standalone application development and I am working on fixing the issue in our existing application. I am running with an issue where the controls inside NSView are getting cut off at bottom and right side of NSView..I am using Xcode 11.3 in macOS Mojave 10.14

I would like to implement scroll bars horizontally and vertically to NSView so that i can be able to view the controls that are getting cut off at the bottom and right side of NSView. Can you please suggest on how to implement scrolling for MacOS NSView?

Kamal
  • 453
  • 1
  • 10
  • 22

1 Answers1

0

NSScrollView provides scroll bars.

The controls inside NSView are cut off, example:

enter image description here

Select the view in IB. Choose menu Editor -> Embed In -> Scroll View

If scrollbars are visible (Setting in System Prefs):

enter image description here

If scrollbars are invisible:

enter image description here

Resize the NSScrollView if needed and add constraints between the scroll view and its superview or sibling views.

Enlarge the Custom View and constrain the size of the Custom View by adding size constraints or constraints between the Custom View and its subviews.

Constrain the location of the Custom View to the topleft of its superview to remove the layout errors.

enter image description here

Build, run. The view is scrolled to the bottom. If you want to start scrolled to the top then create a subclass of NSView, override isFlipped and return true. Set the class of the Custom View in IB to this class.

override var isFlipped: Bool {
    get {
        return true
    }
}
Willeke
  • 14,578
  • 4
  • 19
  • 47
  • As per step #2 will the NSScrollView gets added automatically ? And as per step #3 do we need to resize the scroll view and add constraints in the IB itself or through programatically. Please suggest – Kamal Aug 07 '20 at 04:48
  • Yes embed in scroll view to my view. Scrolls still not getting appeared.. Anything needs to be done still – Kamal Aug 07 '20 at 08:04
  • I'll add images. – Willeke Aug 07 '20 at 08:07
  • Can you please add the images regarding the process that needs to be done for the implementation of scroll bars to NSView? – Kamal Aug 07 '20 at 18:30
  • I have implemented the steps as mentioned by embedding the scroll view, setting the size of the scroll view and adding constraints but still the scrolls are not getting appeared. Is there any problem related to the addition of the constraints ? Can you please share the constraints that you have provided? – Kamal Aug 09 '20 at 03:59
  • Is the view scrollable? While debugging in Xcode choose Menu Debug -> View Debugging -> Capture View Hierarchy. Does the Custom View fit inside its superview? – Willeke Aug 09 '20 at 10:39
  • No the view is not scrollable, Yes the custome view gets fit inside the super view – Kamal Aug 10 '20 at 07:59
  • If the Custom View fits inside its superview then there's nothing to scroll. If you want to see disabled scroll bars then set Show scroll bars to Always in the System Prefs. – Willeke Aug 10 '20 at 08:55
  • Sorry i had read your comment wrong... custom view has lots of controls that are getting cut off at the bottom and right side of view.. – Kamal Aug 10 '20 at 09:15
  • If the controls are clipped by the custom view then enlarge the custom view. This wasn't in the answer, my bad. – Willeke Aug 10 '20 at 09:29
  • Can you please share the sample code you have done for the implementation so that i can compare and check on what is actually missing out – Kamal Aug 10 '20 at 09:58
  • Here's the storyboard: http://www.filedropper.com/mainstoryboard – Willeke Aug 13 '20 at 09:17
  • Thank you for the storyboard. I am looking into it . If i have any quereis i will let you know.. Thanks a lot – Kamal Aug 13 '20 at 10:15