Skip navigation.
 
mlUI elements in custom view mess up drawing
FROM : Antonio Nunes
DATE : Tue Oct 14 15:38:13 2008

Hi,

I have a custom view that draws half a frame and a gradient:

- (void)drawRect:(NSRect)rect {

   // This results in darker separator line at left side.
   [[NSColor colorWithCalibratedWhite:0.18 alpha:1.0] set];
   NSRectFill(NSMakeRect(NSMinX(rect), NSMinY(rect), 1, NSHeight(rect)));

   // This results in lighter separator line along bottom.
   [[NSColor colorWithCalibratedWhite:0.41 alpha:1.0] set];
   NSRectFill(NSMakeRect(NSMinX(rect) + 1, NSMinY(rect), NSWidth(rect) - 
1, NSHeight(rect)));

   // Draw background
   NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:
[NSColor colorWithCalibratedWhite:0.63 alpha:1.0] endingColor:[NSColor 
colorWithCalibratedWhite:1.0 alpha:1.0]];
   [gradient drawInRect:NSMakeRect(NSMinX(rect) + 1, NSMinY(rect) + 1, 
NSWidth(rect), NSHeight(rect) - 1) angle:90.0];

}

In Interface Builder I set an Async progress indicator and a text 
field as subviews of the custom view. When I turn off the progress 
indicator however, or when I update the string value of the text 
field, the drawing from the drawRect method above is drawn offset from 
its origin, instead drawing at the origin of either of the subviews, 
resulting in spurious lines being drawn where there should only be 
background (the gradient). (You can see a screenshot of the effect 
here: http://sintraworks.com/private/RenderingMess.png)

As you can see from the image it looks like the view first draws 
itself correctly, then gets drawn for each of the other subviews, with 
its origin offset to match the origin of the subview in question. I 
don't understand why this happens.

I have tried several workarounds in IB, among others by promoting the 
async arrows and text field to not be subviews of the custom view, but 
simply sit on top of it, but none of the solutions seems to make any 
difference. Any pointers as to what the issue may be and how I can 
solve it?

Kind Regards,
António Nunes
SintraWorks

-----------------------------------------
Forgiveness is not an occasional act;
it is a permanent attitude.

--Martin Luther King, Jr
-----------------------------------------

Related mailsAuthorDate
mlUI elements in custom view mess up drawing Antonio Nunes Oct 14, 15:38
mlRe: UI elements in custom view mess up drawing Benjamin Stiglitz Oct 14, 15:43
mlRe: UI elements in custom view mess up drawing Graham Cox Oct 14, 15:44
mlRe: UI elements in custom view mess up drawing Antonio Nunes Oct 14, 16:16