Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (23 sloc) 866 Bytes
// Copyright 2009 Max Howell
#import "MBImageView.h"
@implementation MBImageView
-(void)setFrame:(NSRect)newFrame
{
// center the NSImageView in the NSScrollArea
// http://web.mac.com/mabi99/marcocoa/blog/Entries/2008/1/1_Centered_Image_inside_a_Scroll_View.html
NSSize superSize = ((NSClipView*)_superview).frame.size;
NSSize imageSize = ((NSImage*)[self image]).size;
newFrame.size.width = MAX(imageSize.width, superSize.width);
newFrame.size.height = MAX(imageSize.height, superSize.height);
if(imageSize.width > superSize.width)
newFrame.origin.x = (superSize.width-imageSize.width)/2;
else
newFrame.origin.x = 0; // otherwise off by one errors seem to propogate
[super setFrame:newFrame];
}
/** pin content as expected, not bottom-left! */
-(BOOL)isFlipped
{
return true;
}
@end