• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: programmatically drawing an NSImageView in an NSView subclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: programmatically drawing an NSImageView in an NSView subclass


  • Subject: Re: programmatically drawing an NSImageView in an NSView subclass
  • From: Shawn Erickson <email@hidden>
  • Date: Sat, 10 Jan 2004 11:56:25 -0800

On Jan 10, 2004, at 11:31 AM, Benjamin Salanki wrote:

hi,

i want to draw some NSImageViews in my NSView subclass.

i use the following code in my drawRect: method:

- (void)drawRect:(NSRect)rect
{
//drawing code here
int numberOfFiles = [_files count];
int i;
for(i=0;i<numberOfFiles;i++)
{
NSImageView* theView = [[NSImageView alloc]
initWithFrame:NSMakeRect(15+(i%3)*85, 15+(i/3)*72, 70.00, 56.00)];
[theView setImageFrameStyle:NSImageFramePhoto];
[theView setImageAlignment:NSImageAlignCenter];
[theView setImageScaling:NSScaleProportionally];
[theView setImage:[[NSImage alloc] initWithContentsOfFile:[_files
objectAtIndex:i]]];
[theView setTag:i];
[theView setTarget:self];
[theView setAction:@selector(what:)];
}
}

the calculations get done and everything, CPU cycles get eaten, but the
view does not display the imageViews. I tried to replace the code and
draw simple rects with NSBezierPath, and that works like a charm.

any ideas?

What are you trying to do exactly? Not in code but what do you want the end visual result to be and what items are or are not controls?

You are creating a NSImageView which is a NSControl subclass yet you are not adding them to a containing view so they will not be displayed (their draw methods will not be called). You should not attempt to create such items in you draw routine but instead when your view sub-class is initialized and/or as images are added to custom view. In fact if your custom view contains nothing but some type of matrix of image views or other standard view classes you do not need to override the default drawRect method.

Anyway you may want to consider using a NSMatrix of NSImageViews or not using image views but directly drawing the images yourself. We cannot help with this end of things without knowing what the end goal is for your application.

-Shawn
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >programmatically drawing an NSImageView in an NSView subclass (From: Benjámin Salánki <email@hidden>)

  • Prev by Date: Executing Javascript in webview
  • Next by Date: Large number support (BIG INT)
  • Previous by thread: programmatically drawing an NSImageView in an NSView subclass
  • Next by thread: Re: programmatically drawing an NSImageView in an NSView subclass
  • Index(es):
    • Date
    • Thread