• 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
Drawing custom NSSegmentedControl/Cells
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Drawing custom NSSegmentedControl/Cells


  • Subject: Drawing custom NSSegmentedControl/Cells
  • From: Ken Tabb <email@hidden>
  • Date: Wed, 4 Jan 2006 18:11:34 +0000

Happy New Year folks!

I've subclassed NSSegmentedControl / NSSegmentedCell with a view to customising their appearance, but I'm having trouble getting the drawing working properly. Specifically I can't easily stop the superclass from drawing the end caps or the separator lines between the segments.

In my segmented control, there's nothing special going on... drawRect just calls [super drawRect:rect].

In my segmented cell, there are 2 methods that seem to work together to handle drawing: -drawSegment:inFrame:withView: and the inherited NSCell's -drawWithFrame:inView:

The first method, -drawSegment:inFrame:withView: allows me to customise a segment's "inner" appearance, by passing me the rectangular content area that contains a specific segment. This method doesn't seem to allow me to access the non-segment areas though, i.e. the end caps of the control, or the separator lines (which lie between the rectangular areas passed in as the 'frame' parameter).

With the inherited NSCell -drawWithFrame:inView: method, if I call [super ...] I get the standard Aqua caps, separator lines and drop shadow border drawn behind my nice new customised segment rectangles, making my GUI look a bit like Frankenstein's monster. If I don't call [super ...] then my cell's -drawSegment:inFrame:withView: method doesn't get called at all.

I guess I could override -drawWithFrame:inView:, not call [super ...] at all in it, and instead do my own "control drawing" (i.e. the end caps etc. as per my desired appearance) and call [self - drawSegment:inFrame:withView:] for each segment. This would require my control to track the rects for each segment (there doesn't seem to be an API for that, so I'd be duplicating it in my custom control). Also, would this allow for clicking on an end cap to mean "treat that as if the user clicked the first (or last) segment even though they actually clicked the end cap"?

Is this the right approach or am I, as ever, barking up the wrong tree?

Thanks in advance for any corrective therapy you can give me,
Ken

p.s. Needless to say customising the appearance of an NSButton / NSButtonCell in a similar fashion to this was a doddle...

- - - - - - - - - -
Dr. Ken Tabb
Mac & UNIX Developer - Health & Human Sciences
Machine Vision & Neural Network researcher - School of Computer Science
University of Hertfordshire, UK
http://www.health.herts.ac.uk/ken/

Certified non-Microsoft Solution Provider

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Custom Objects in an NSTextView
  • Next by Date: Re: perform ... afterDelay? [solved]
  • Previous by thread: **JOB LISTING**
  • Next by thread: MainMenu
  • Index(es):
    • Date
    • Thread