365Cocoa

A snippet of Objective-C code per day, 365 days long.
Written by Pieter Omvlee, developer and owner of Bohemian Coding.

Mar 25

Day 27: toolbarHeight

The following snippet is taken from somewhere in Apple’s docs. It’s nice reminder for those who need to know the height of an NSToolbar:

- (float)toolbarHeight
{
  NSToolbar *toolbar;
  float toolbarHeight = 0.0;
  NSRect windowFrame;
  
  toolbar = [self toolbar];
  
  if(toolbar && [toolbar isVisible]) {
    windowFrame = [NSWindow contentRectForFrameRect:[self frame]
                                          styleMask:[self styleMask]];
    toolbarHeight = NSHeight(windowFrame) - NSHeight([[self contentView] frame]);
  }
  
  return toolbarHeight;
}

  1. 365cocoa posted this