Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 16, 2009, 01:34 AM   #1
medasmx
macrumors member
 
Join Date: Nov 2008
bounds

I have been trying to use bounds in a custom cell program, as described in a prior post "drawAtPoint". So I wrote a simple customview program, whose code is below...

Code:
@implementation AppController

- (id)initWithFrame:(NSRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
    }
    return self;
}

- (void)drawRect:(NSRect)rect {
    NSRect myBounds=[self bounds];
	[[NSColor greenColor]set];
	NSRectFill(myBounds);
	
	NSPoint myPoint1=myBounds.origin;
	NSPoint myPoint2=NSMakePoint(50,50);
	
	[[NSColor blackColor]set];
	myPath=[NSBezierPath bezierPath];
	
	[myPath setLineWidth:3];
	[myPath moveToPoint:myPoint1];
	[myPath lineToPoint:myPoint2];
	[myPath stroke];
}

@end
This works, drawing a simple green box with a diagonal black line in the bottom, left corner. However, when using bounds in the bottom code...

Code:
-(void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
{
	NSRect myRect=NSZeroRect;
	NSRect myBounds=[self bounds];
	NSRect		anInsetRect = NSInsetRect(cellFrame,10,10);
	NSRect		aTextBox = NSMakeRect(anInsetRect.origin.x,anInsetRect.origin.x,25,25);
	[[NSColor redColor]set];
	NSRectFill(NSInsetRect(cellFrame,4,4));
	[string drawInRect:aTextBox withAttributes:attributes];
}
I get the error "invalid initializer". Is bounds inappropriate for drawWithFrame:inView:? Any other ideas? Thanks.

Adam
medasmx is offline   0 Reply With Quote
Old Jun 16, 2009, 08:08 AM   #2
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
Look up the bounds method in the documentation, and you'll see that it doesn't exist for NSCell or any of its subclasses. It's strictly an NSView method, and NSViews do not work the same as NSCells. When drawing with an NSCell you should only be using the cellFrame parameter that gets passed to your code.
kainjow is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
How do you set cursor initial cursor position and NSTextField bounds? DavidBlack Mac Programming 3 Mar 1, 2014 11:46 AM
UIView Layer Bounds Not Showing Correctly Zoyt iPhone/iPad Programming 2 Feb 23, 2014 10:53 PM
Why does NSArray throw out of bounds errors? ArtOfWarfare Mac Programming 2 May 3, 2013 11:18 AM
index 1 beyond bounds [0 .. 0] Core Data luke3 iPhone/iPad Programming 3 Jul 6, 2012 12:44 PM

Forum Jump

All times are GMT -5. The time now is 02:41 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC