• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
UI elements in custom view mess up drawing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

UI elements in custom view mess up drawing


  • Subject: UI elements in custom view mess up drawing
  • From: Antonio Nunes <email@hidden>
  • Date: Tue, 14 Oct 2008 14:38:13 +0100

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
-----------------------------------------




_______________________________________________

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


  • Follow-Ups:
    • Re: UI elements in custom view mess up drawing
      • From: Graham Cox <email@hidden>
    • Re: UI elements in custom view mess up drawing
      • From: Benjamin Stiglitz <email@hidden>
  • Prev by Date: [CODE] JPDurationToDecimalNumberFormatter
  • Next by Date: Re: UI elements in custom view mess up drawing
  • Previous by thread: [CODE] JPDurationToDecimalNumberFormatter
  • Next by thread: Re: UI elements in custom view mess up drawing
  • Index(es):
    • Date
    • Thread