开发者

NSTextField draw programmatically to a view

I have this view called scrollView. It's a NSScrollView type. I want to draw in a text manually without using the interface builder.

I made a NSTextField a开发者_JAVA百科nd set the string value inside it to "Hello World," so how do I add it to the scrollView?

Here's the basic structure of what I am trying to do:

NSTextField *usernameText = [[NSTextField alloc] init];
[usernameText setStringValue:username];

NSView *subView = [[NSView alloc] init];
[subView addSubview:usernameText];

[scrollView addSubview:subView ];


Your question is classified in ios but based on the context and "NS" I'm going to go with the mac version.

You should look at Apple's "Text System User Interface Layer Programming Guide" Specifically the section titled putting an NSTextView object in an NSScrollView here.

Basically you first set up the NSScrollView. Then you create and configure the NSTextView to go in the NSScrollView finally you combine the pieces.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜