• 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: NSImageView's picture frame? (Warning: Ugly Hack!)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImageView's picture frame? (Warning: Ugly Hack!)


  • Subject: Re: NSImageView's picture frame? (Warning: Ugly Hack!)
  • From: "John C. Randolph" <email@hidden>
  • Date: Thu, 31 Jan 2002 14:51:54 -0800

On Thursday, January 31, 2002, at 09:55 AM, Michael B. Johnson wrote:

From: "Michael B. Johnson" <email@hidden>
To: email@hidden

Okay, I have just officially spent *too much time* trying to figure out
the right NSRect*/CG*/NSBezierPath* magic to draw the little picture
frame that NSImageView draws around an image.

Has anybody already done this successfully and is willing to share? I'd
be ever so grateful...



Just to be clear: I'm *not* trying to do this in a subclass of NSImageView - I'm trying to do this is my own subclass of NSView. I don't want to subclass NSImageView, because (among other things), I want to control the opacity of the background, and NSImageView's is always completely opaque.

Wave,

I believe that frame is built up from a bunch of little images, the way that the scrollbar thumbs are. One way to do this, would be to make an NSImageView instance, size it to match your view, and call its drawRect: from your own -drawRect: method, e.g:


BezelView.h:

#import <Cocoa/Cocoa.h>

@interface BezelView : NSView
{
}

- (void)drawRect:(NSRect)aRect;

@end


BezelView.m:

#import "BezelView.h"

static NSImageView *foo;

@implementation BezelView

+ (void) initialize
{
if (!foo)
foo = [[NSImageView alloc] initWithFrame:NSMakeRect(0,0,10,10)];
[foo setImageFrameStyle:NSImageFrameGrayBezel];
}

/* NSImageFrameNone-an invisible frame
NSImageFramePhoto-a thin black outline and a dropped shadow
NSImageFrameGrayBezel-a gray, concave bezel that makes the image look sunken
NSImageGroove-a thin groove that looks etched around the image
NSImageFrameButton-a convex bezel that makes the image stand out in relief, like a button
*/

- (void)drawRect:(NSRect)aRect
{
[foo setBounds:[self bounds]];
[foo drawRect:aRect];
//...
}

@end

Of course, this will result in an opaque background. If you want to fade the frame, then draw into an NSImage first and composite it in place.

-jcr

John C. Randolph <email@hidden> (408) 974-8819
Sr. Software Engineer, Cocoa Evangelism
Apple Worldwide Developer Relations


References: 
 >Re: NSImageView's picture frame? (From: "Michael B. Johnson" <email@hidden>)

  • Prev by Date: Modification dates and AFP
  • Next by Date: Re: InputServer/Manager
  • Previous by thread: Re: NSImageView's picture frame?
  • Next by thread: NSTextStorage subclass and word selection
  • Index(es):
    • Date
    • Thread