简体   繁体   中英

How do I embed a child view within an NSTextView?

I have a text view, in which I would like to place other views, like so:

=====================================
= This is an editable NSTextView... =
= /-------\                         =
= |Subview|                         =
= \-------/                         =
= other text.                       =
=====================================

There are NSTextAttachment s, but they seem to only be well-suited for images. How can I insert into the text a fully-functional NSView with keyboard/mouse interaction and subviews itself, etc?

You might want to check out the NSTextContainer and NSLayoutManager classes:

' NSTextContainer defines rectangular regions, but you can create subclasses that define regions of other shapes, such as circular regions, regions with holes in them, or regions that flow alongside graphics. '

' An NSLayoutManager uses NSTextContainer to determine where to break lines, lay out portions of text, and so on. '

The Cocoa Text Architecture Guide might be handy as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM