IB_DESIGNABLE从不适用于NSTextFieldCell



我有一个NSTextFieldCell子类,在实现中只有这个代码:

- (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;
}

在标题上,我在@interface之前IB_DESIGNABLE

此类用于在 NSTextField 上垂直居中文本,但文本永远不会显示在界面生成器的中心。此类从不在接口生成器上呈现。为什么?

不幸的是,IBDESIGNABLE仅适用于NSView和UIView的后代。

相关内容

最新更新