2

I have a NSTextFieldCell subclass with this only code in the implementation:

- (NSRect)drawingRectForBounds:(NSRect)theRect
{
    // Get the parent's idea of where we should draw
    NSRect newRect = [super drawingRectForBounds:theRect];

    // When the text field is being 
    // edited or selected, we have to turn off the magic because it screws up 
    // the configuration of the field editor.  We sneak around this by 
    // intercepting selectWithFrame and editWithFrame and sneaking a 
    // reduced, centered rect in at the last minute.
    if (mIsEditingOrSelecting == NO)
    {
        // Get our ideal size for current text
        NSSize textSize = [self cellSizeForBounds:theRect];

        // Center that in the proposed rect
        float heightDelta = newRect.size.height - textSize.height;  
        if (heightDelta > 0)
        {
            newRect.size.height -= heightDelta;
            newRect.origin.y += (heightDelta / 2);
        }
    }

    return newRect;
}

on the header I have IB_DESIGNABLE before @interface

This class is for centering the text vertically on a NSTextField but the text never shows centered on interface builder. This class never renders on interface builder. Why?

UFO
  • 219
  • 3
  • 8

1 Answers1

2

Unfortunately, IBDESIGNABLE only works for descendants of NSView and UIView.

Elwisz
  • 654
  • 1
  • 6
  • 18
  • why Apple bothers to do stuff? Every API is half-cooked to the bone. – Duck Jun 30 '17 at 13:30
  • @SpaceDog NSCell based controls are soon to be deprecated - it probably wouldn't have been worth the effort to add support for them. – Elwisz Jul 02 '17 at 18:58
  • OK but IB_Designable works like crap for all controls. It is a fountain of half-cooked stuff. – Duck Jul 02 '17 at 19:09