Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The other answers didn't work for multiple lines. Therefore I initially continued using the undocumented <code>cFlags.vCentered</code> property, but that caused my app to be rejected from the app store. I ended up using a modified version of Matt Bell's solution that works for multiple lines, word wrapping, and a truncated last line:</p> <pre><code>-(void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView { NSAttributedString *attrString = self.attributedStringValue; /* if your values can be attributed strings, make them white when selected */ if (self.isHighlighted &amp;&amp; self.backgroundStyle==NSBackgroundStyleDark) { NSMutableAttributedString *whiteString = attrString.mutableCopy; [whiteString addAttribute: NSForegroundColorAttributeName value: [NSColor whiteColor] range: NSMakeRange(0, whiteString.length) ]; attrString = whiteString; } [attrString drawWithRect: [self titleRectForBounds:cellFrame] options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin]; } - (NSRect)titleRectForBounds:(NSRect)theRect { /* get the standard text content rectangle */ NSRect titleFrame = [super titleRectForBounds:theRect]; /* find out how big the rendered text will be */ NSAttributedString *attrString = self.attributedStringValue; NSRect textRect = [attrString boundingRectWithSize: titleFrame.size options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin ]; /* If the height of the rendered text is less then the available height, * we modify the titleRect to center the text vertically */ if (textRect.size.height &lt; titleFrame.size.height) { titleFrame.origin.y = theRect.origin.y + (theRect.size.height - textRect.size.height) / 2.0; titleFrame.size.height = textRect.size.height; } return titleFrame; } </code></pre> <p>(This code assumes ARC; add an autorelease after attrString.mutableCopy if you use manual memory management)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload