问题
How do I insert emoji into an NSTextView
without moving the line down?
If I insert an emoji character into an NSTextView
, the whole line will shift down a couple pixels. If I remove the emoji character, it will move back up to its original position.
On the other hand, if I insert an emoji into an NSTextField
, the line doesn't move at all, even when the text in the line is the same font and size as it was in the NSTextView
.
You can see this behavior in TextEdit. When you are typing in the main editor area (an NSTextView
), emoji make the lines move down. When you are typing in the Find search bar (NSTextField
) emoji don't affect the line position.
I've tried setting typingAttributes
with various NSParagraphStyle
settings (lineHeight
, lineSpacing
, lineHeightMultiple
, max/minLineHeight
) and also raising or lowering the baseline to no avail. In fact, some of these settings don't help the emoji behavior, but they do mess up the vertical alignment of the spelling error indicators.
来源:https://stackoverflow.com/questions/39460470/how-to-insert-emoji-into-nstextview-without-shifting-the-line-down