title: cocoa : how to add an icon to NSTabViewItem using the method drawlabel:inRect in cocoa?
body: <p>I want to add an icon to the <code>NSTabViewItem</code> with some text.</p>
  
  <p>Please help me with the code in <code>drawLabel:inRect:</code> method.</p>
  
  <pre><code>- (id)initWithCoder:(NSCoder *)decoder
  {
  [super initWithCoder:decoder];
  
  tabCell = [[NSBrowserCell alloc] initImageCell:[NSImage 
  imageNamed:@"xyz"]];
  
  [tabCell setLeaf:YES];
  [tabCell setFont:[[self tabView] font]];
  [tabCell setStringValue: [self label]];
  
  return self;
  }
  
  - (void)drawLabel:(BOOL)shouldTruncateLabel inRect:(NSRect)tabRect
  {
  { //  modify the rect a tad so the cell draws properly..
      tabRect.origin.y += 2;
      tabRect.size.width += 16;
  }
  
  [tabCell drawWithFrame:tabRect inView:[self tabView]];
  }
  
  
  - (NSSize)sizeOfLabel:(BOOL)shouldTruncateLabel
  {
  NSSize superSize = [super sizeOfLabel:shouldTruncateLabel];
  NSImage *icon = [tabCell image];
  
  superSize.width += [icon size].width-4;
  
  return superSize;
  }
  </code></pre>
  
  <p>I am able to add an icon to the <code>NSTabViewItem</code> but the icon is coming out of the tab because of its big size. How can I maintain the size of icon to stay within the <code>TabViewItem</code>?</p>