how to align contents of NSScrollView

Discussion in 'Mac Programming' started by anni.saini, Feb 8, 2010.

  1. anni.saini macrumors newbie

    Joined:
    Jul 15, 2009
    #1
    I have created Rect on NSScrollView, at present its position is Top-Left on the scroll view
    --Figure 1 below

    I want to shift it to Top-Center like this
    --Figure 2 below

    Can anybody help me on this...
    how to do that?

    regards,
    Anni
     

    Attached Files:

  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    What do you mean "on NSScrollView"? NSScrollViews usually contain a document view which is the main body of the scroll view that gets scrolled. In this view you would draw what you want horizontally centered.

    Have a look at the Scroll View Programming Guide.
     
  3. anni.saini thread starter macrumors newbie

    Joined:
    Jul 15, 2009
    #3
    hi kainjow,

    I forgot to mention, I mean NSView is added as a sub view on the NSScrollView.
    If you could show me small code snippet for this that would be great... :)

    thanks for reply.
     
  4. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    I still don't understand how you want this setup. Is this view floating outside of the document view and anchored to the top of the scroll view? Or does it scroll just like your document view? Those are two very different setups.
     
  5. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #5
    If you want it fixed in place, I would try something like this:

    NSRect viewFrame = [[theScollView contentView] frame];

    to get the interior size of the view, then set the corner of the rectangle like this:

    theRectangle.origin.x = ( ( viewFrame.size.width - theRectangle.size.width ) / 2.0 ) + viewFrame.origin.x;
     

Share This Page