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

satyam90

macrumors regular
Original poster
Jul 30, 2007
242
0
Bangalore, India
I inherited MyView class from NSView. In a controllers init method I am creating a panel
Code:
NSPanel *panel = [[[NSPanel alloc] initWithContentRect:NSMakeRect( 0., 0., 270., 65. ) 
       styleMask:NSBorderlessWindowMask 
       backing:NSBackingStoreBuffered defer:NO] autorelease];
.
.
.
.
MyView *view = [[[KABubbleWindowView alloc] initWithFrame:[panel frame]] autorelease];
	[view setTarget:self];
	[view setAction:@selector( _bubbleClicked: )];
	[panel setContentView:view];
.
.
.
.
	return ( self = [super initWithWindow:panel] );

Later in one of the methods I am setting the title, icon and text as follows
Code:
	id ret = [[[self alloc] init] autorelease];
	[ret setTitle:title];
	if( [text isKindOfClass:[NSString class]] ) [ret setText:text];
	else if( [text isKindOfClass:[NSAttributedString class]] ) [ret setAttributedText:text];
	[ret setIcon:icon];
	return ret;
Its working fine upto this point. But my problem is that if title is more than the width of panel ie 270 pixels or if text height more than 65 pixels, the text is crossing the border and not able to view it. No scroll bars are to be there in that. It's a restriction.
So, I want to increase the size of view & panel dynamically depending on width and height of the text. What's the procedure to achieve this.
 
NSAttributedString has a few methods (size, and boundingRectWithSize:eek:ptions:) which can help you determine if the text field/view with a given string is too large. Then you can size the views and panel via setFrame:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.