Can't get View to be drawn in NSScrollView

醉酒当歌 提交于 2019-12-11 05:58:29

问题


I am confused about how to implement a NSScrollView in the most basic way, so I will describe exactly what I do and hope that it is just to late for me to find my error:

  1. Create Xcode project.
  2. Adding a NSScrollView into MainMenu.xib.
  3. Creating new class inherited from NSView with the drawing method:

    (void)drawRect:(NSRect)dirtyRect
    {
    [super drawRect:dirtyRect];
    [[NSColor redColor] set];
    NSRectFill(dirtyRect);
    }
    
  4. Define the view of the NSScrollView to be that new class.

I expected to see a NSScrollView with a red background. Instead, I see the scroll view with no modification.


回答1:


The problem is auto layout. Turn it off and it will work fine.



来源:https://stackoverflow.com/questions/19663776/cant-get-view-to-be-drawn-in-nsscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!