Mac Forums

Mac Forums (
-   OS X - Development and Darwin (
-   -   Heeeeeelp! How to write String into NSView? (

Yodda_Hunter 01-17-2014 02:43 PM

Heeeeeelp! How to write String into NSView?
guys, i want the user to scroll while reading text,but the deal is that the multiple line label doesn't support scrolls and Scroll View doesn't support stringValue. need some help

Raz0rEdge 01-17-2014 03:32 PM

Threads merged - please don't post the same question into multiple threads..

Might I suggest that you do some searching in your favorite search engine for your answer or buy a book about OS X/iOS development..

Mark FX 01-19-2014 04:13 PM

You can put the multiline label in the scroll view, but I did restle a bit with it myself.

I placed a multiline label on a window from the object library, and also a scroll view from the object library, then I created two IBOutlet properties in my AppDelegate, one of a NSTextField called myMultilineLabel, and one of a NSScrollView class called myScrollView, then finally connect them in Interface Builder too the Label and Scroll View on the window.

next I sized the label too what it needed to be, to hold the text it was going to hold, then I selected the scroll view, and double clicked it's interior to select it's content view, then I resized the content view with the inspectors size tab, by entering the sizes to the labels size.

then in the AppDelegate's applicationDidBecomeActive: method, I entered the code below.


    NSString *myString = [[NSString alloc] initWithFormat:@"line 1\nLine 2\nLine 3\nLine 4\nLine 5\nLine 6\n"];
    [myMultiLabel setStringValue:myString];
    [myScrollView addSubview:myMultiLabel];
    [myScrollView setDocumentView:myMultiLabel];

A second way to achieve this is to select your multi label, and then from Xcode's editor menu, select Embed In > Scroll View.
But as of writing I did'nt get this method to work very well, but will let you know if I can.

Regards Mark

All times are GMT -4. The time now is 09:42 AM.

Powered by vBulletin
Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.