Re: Placing an Image next to a UI element
Re: Placing an Image next to a UI element
- Subject: Re: Placing an Image next to a UI element
- From: Fritz Anderson <email@hidden>
- Date: Fri, 25 Nov 2011 11:41:34 -0600
On 25 Nov 2011, at 7:45 AM, David Mirabito wrote:
> NSView *aview = theOffendingNSTextView;
Is this in fact an NSTextView, or do you mean NSTextField?
> NSView *superView = [aview superview];
>
> NSRect oldframe = [aview frame];
>
> NSRect newFrame = NSMakeRect(
> oldframe.origin.x + oldframe.size.width + 26,
> oldframe.origin.y,
> oldframe.size.height,
> oldframe.size.height);
So even if the view being annotated is 300 pt tall, and the icon image is 32 pt tall, you're going to make the icon view 300 x 300? And if the origin of the annotated view is 24 pt (remember that's measured _from the bottom_, you're going to align the annotation at the bottom of the annotated view? If your text views are the only ones you've tried that are taller than the others you've annotated, the annotation view will ride lower than you expect.
Also, many view frames differ in size and origin from the visually-apparent frames. To diagnose, try subclassing your enclosing view (if you haven't already), and in drawRect: iterate through the subviews and draw rectangles around their frames. A very cursory skim of the class references don't show me anything that would help you get the layout rects, but maybe you can hold your nose and derive the layout rects from the frames empirically.
Maybe the 10.7 autolayout methods could help you; it may be good enough to align your annotations with the annotated views' baselines.
> NSImageView *img = [[NSImageView alloc] initWithFrame:newFrame];
> [img setImage:[NSImage imageNamed:@"NSInvalidDataFreestandingTemplate"]];
This isn't your problem, but never use literal strings for Cocoa's exported global strings. You don't know whether the constant value is @"com.apple.aStr", and the symbol they published to the API is NSViewFrobbingA.
> [superView addSubview:img];
— F
_______________________________________________
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