2015-01-02 1 views
2

У меня есть подкласс NSTextFieldCell с этим только кодом в реализации:IB_DESIGNABLE никогда не работает для 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; 
} 

на заголовке я имею IB_DESIGNABLE перед тем @interface

Этот класс предназначен для центрирования текста по вертикали на NSTextField, но текст никогда не отображается в центре интерфейса. Этот класс никогда не оказывает на интерфейс конструктора. Зачем?

ответ

1

К сожалению, IBDESIGNABLE работает только для потомков NSView и UIView.

+0

Почему Apple потрудилась? Каждый API наполовину варится до костей. – SpaceDog

+0

@SpaceDog Элементы управления, основанные на NSCell, скоро будут устаревать - вероятно, не стоит пытаться добавить поддержку для них. – Elwisz

+0

OK, но IB_Designable работает как дерьмо для всех элементов управления. Это источник полуфабрикатов. – SpaceDog