【问题标题】:IB_DESIGNABLE never works for NSTextFieldCellIB_DESIGNABLE 从不适用于 NSTextFieldCell
【发布时间】:2015-02-28 23:18:50
【问题描述】:

我有一个 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 上垂直居中文本,但文本从不显示在界面生成器上。此类永远不会在界面生成器上呈现。为什么?

【问题讨论】:

    标签: xcode macos cocoa interface-builder ibdesignable


    【解决方案1】:

    很遗憾,IBDESIGNABLE 仅适用于 NSView 和 UIView 的后代。

    【讨论】:

    • 苹果为什么要费心做事?每个 API 都是半生不熟的。
    • @SpaceDog 基于 NSCell 的控件即将被弃用 - 为它们添加支持可能不值得。
    • 好的,但是 IB_Designable 对所有控件都像废话。这是半熟的东西的喷泉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-15
    相关资源
    最近更新 更多