Re: Problem adding subview to NSScroller subclass
Re: Problem adding subview to NSScroller subclass
- Subject: Re: Problem adding subview to NSScroller subclass
- From: Graham Cox <email@hidden>
- Date: Sun, 08 Jul 2012 11:04:06 +1000
On 07/07/2012, at 6:38 PM, Gideon King wrote:
> Has anybody successfully added a subview to an NSScroller?
Yes, but more recently I took it out again and moved that extra view elsewhere, because on Lion/Mountain Lion, these scroll areas are handled differently and the presence of an extra view is detected and used to revert the scroller to the "legacy" scrollbar design, which is going to look increasingly out of place as apps adopt the new one. This extra special-casing could also be affecting whether and how your view is drawn. That said my code worked on Lion, it just used the legacy scrollbars.
My subclass of NSScrollView only overrides one method - tile, and adds a property, 'placard' which is the extra view to insert. I believe this code originally was derived from someone else's example I found on the web in about 2003, so I'm not trying to claim it as my own. It does work however.
- (void) setPlacard:(NSView *)inView
{
[inView retain];
if (nil != placard)
{
[placard removeFromSuperview];
[placard release];
}
placard = inView;
[self addSubview:placard];
}
- (void)tile
{
[super tile];
if (placard && [self hasHorizontalScroller])
{
NSScroller *horizScroller;
NSRect horizScrollerFrame, placardFrame;
horizScroller = [self horizontalScroller];
horizScrollerFrame = [horizScroller frame];
placardFrame = [placard frame];
// Now we'll just adjust the horizontal scroller size and set the placard size and location.
horizScrollerFrame.size.width -= placardFrame.size.width;
[horizScroller setFrameSize:horizScrollerFrame.size];
placardFrame.origin.x = NSMinX(horizScrollerFrame);
// Move horizontal scroller over to the right of the placard
horizScrollerFrame.origin.x = NSMaxX(placardFrame);
[horizScroller setFrameOrigin:horizScrollerFrame.origin];
// Adjust height of placard
placardFrame.size.height = horizScrollerFrame.size.height;// + 1.0;
placardFrame.origin.y = [self bounds].size.height - placardFrame.size.height;
// Move the placard into place
[placard setFrame:placardFrame];
}
}
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden