Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I draw a background like the nstoolbar

Tags:

cocoa

drawing

I am trying to make a custom toolbar to use anywhere. I want the background to look like the gray that the nstoolbar has. The color is used in several places like the top of Safari or Mail.

Does anyone know of an easy way to draw it? Or use the nstoolbar somewhere other than the top of a window?

like image 877
joels Avatar asked Dec 06 '25 07:12

joels


2 Answers

You'll want to create an NSGradient with two colors (the "top" and "bottom"), then draw the gradient into the desired rectangle ([self bounds]?). You can get system colors from the NSColor API reference (there are class convenience methods for system colors). I'm not sure exactly which the bar uses, but that should be enough info to get started.

like image 197
Joshua Nozzi Avatar answered Dec 10 '25 01:12

Joshua Nozzi


  • Open a standard colour picker in any app (say, TextEdit)
  • Switch to Colour Sliders mode, RGB Sliders submode
  • Click the magnifying glass
  • Click the colour you want to check, anywhere on screen
  • Click the small colour wheel next to the “RGB Sliders” popup menu
  • Select Generic RGB (it should be right under Device RGB, which should be selected)
  • Divide the colour components by 255
  • Feed the resulting values to +[NSColor colorWithCalibratedRed:green:blue:alpha:]
like image 30
Jens Ayton Avatar answered Dec 10 '25 02:12

Jens Ayton