【发布时间】: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