Centering an Image in an NSScrollView
Centering an Image in an NSScrollView
- Subject: Centering an Image in an NSScrollView
- From: jean-michel daix <email@hidden>
- Date: Mon, 01 Jul 2002 09:54:36 +0200
Hi,
As I think many people, I'm trying to centering an Image in a document based
application using an NSScrollView. I mean when I enlarge my window, I want
my image to stay centered in the window. In my custom ImageView I use this
code.
- (BOOL)isFlipped
{
return YES;
}
- (void)drawRect:(NSRect)rect {
[self hideOrShowScrollers]; //Test if the image is bigger than the view
[self centerFrame];
[super drawRect:rect];
}
- (void)centerFrame
{
NSSize scrollViewSize = [[[self superview] superview] frame].size;
NSSize frameSize = [self frame].size ;
NSPoint frameOrigin;
frameOrigin.x = frameOrigin.y = 0.0;
if ( scrollViewSize.width >= frameSize.width )
frameOrigin.x=((long) (scrollViewSize.width-frameSize.width))/2;
if ( scrollViewSize.height >= frameSize.height )
frameOrigin.y=((long) (scrollViewSize.height-frameSize.height))/2;
[[self superview] setFrameOrigin:frameOrigin];
}
Well, it works. Except that sometimes the background is not refreshed (When
using the zoom buttton for exemple), so I think it's not the right method to
do that. May be someone can tell me a better way or how to refresh my
background. Thanks.
-----------------------------------
Jean-Michel DAIX / <email@hidden>
Sorry, I9m French !
visit <
http://www.adforum.com>
_______________________________________________
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.