Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Monaj

macrumors regular
Original poster
May 24, 2009
193
0
Hi all,

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.

So I tried this method:

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.

The code I used is:


Code:
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)];

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

Thanks,

Monaj
 
If you want to omit the scroll view entirely (e.g., make a text view that is attached to another superview and sizes itself to fit its text), you might take a look at NSText. It is, AFAICT, basically a NSTextView without the superview (scroll view parts), and can automagically resize itself.
 
If you want to omit the scroll view entirely (e.g., make a text view that is attached to another superview and sizes itself to fit its text), you might take a look at NSText. It is, AFAICT, basically a NSTextView without the superview (scroll view parts), and can automagically resize itself.

Thanks Sydde for your reply..

Can you please throw some light on how to use NSText object? From its class reference I got that : You usually use instances of its subclass, NSTextView. So I am becoming clueless on how will I represent it in IB and will use it according to my requirements? :confused:

Once again thanks for helping a newbie.
 
To create an NSText in a nib, drop a custom view onto your window, then go to the identity tab in the inspector panel and set its class. In fact, if you set the class to NSTextView, you will get the same result: a text view without the scrollbars that autoresizes itself. However, neither of these work quite as you would hope in Cocoa Simulator, you will probably have to do something in your -awakeFromNib or in your app code to get them to behave properly.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.