如何根据其内容调整NSTextView的大小? [英] How to resize NSTextView according to its content?

查看:408
本文介绍了如何根据其内容调整NSTextView的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在NSTextView中设置一个属性字符串。我想根据其内容增加其高度,最初它设置为一些默认值。

I am trying to set an attributed string within NSTextView. I want to increase its height based on its content, initially it is set to some default value.

所以我试过这个方法:

我在NSTextView中设置内容。当我们在NSTextView中设置一些内容时,其大小自动增加。所以我增加了它的超级视图的高度是NSScrollView到它的高度,但是NSScrollView没有得到完全调整大小,它显示滚动在右边。

I set content in NSTextView. When we set some content in NSTextView its size automatically increases. So I increased height of its super view that is NSScrollView to its height, but NSScrollView is not getting completely resized, it is showing scroller on right.

float xCoordinate = 15.0;

[xContentViewScroller setFrame:NSMakeRect(xCoordinate, 0.0, 560.0, 10.0)];

[[xContentView textStorage] setAttributedString:xContents];

float xContentViewScrollerHeight = [xfContentView frame].size.height + 2;

[xContentViewScroller setFrame:NSMakeRect(xCoordinate, 0.0, 560.0, xContentViewScrollerHeight)]; 

任何人都可以建议我一些方法或方法来解决这个问题。通过做谷歌搜索我发现在UITextView有contentSize方法可以获得其内容的大小,我试图找到类似的方法在NSTextView,但不能得到任何成功:(

Can anyone suggest me some way or method to resolve this issue. By doing google search I found that in UITextView there is contentSize method which can get size of its content, I tried to find similar method in NSTextView but could not get any success :(

推荐答案

向文本视图查询其布局管理器其文本容器,然后强制布局管理器执行布局,然后向布局管理器询问文本容器使用的矩形

Ask the text view for its layout manager and its text container. Then, force the layout manager to perform layout, and then ask the layout manager for the used rectangle for the text container.

另请参见文本系统概述

See also the Text System Overview.

这篇关于如何根据其内容调整NSTextView的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆