Heeeeeelp! How to write String into NSView?

Joined
Jun 8, 2013
Messages
158
Reaction score
0
Points
16
Location
Būr said,Egypt
Your Mac's Specs
MacBook Pro (i5)
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

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,762
Reaction score
2,100
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
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..
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
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.

Code:
    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
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top