中立の垂直整列で表示したいNSTextFieldCellがあります。ここで古い質問とブログエントリのおかげで、私は2つの実用的な解決策を持っています。NSTextFieldCell垂直整列、ソリューションは、水平整列をスカッシュしているようです。
しかし、どちらの解決策でも、セルを右揃えに設定する能力が低下しているようです。誰も私がこれらのソリューションのいずれかを両方の形式のアライメントに対応させるのを助けることができますか?ここ
一の溶液のためのコードである:
@implementation MiddleAlignedTextFieldCell
- (NSRect)titleRectForBounds:(NSRect)theRect {
NSRect titleFrame = [super titleRectForBounds:theRect];
NSSize titleSize = [[self attributedStringValue] size];
titleFrame.origin.y = theRect.origin.y - .5 + (theRect.size.height - titleSize.height)/2.0;
return titleFrame;
}
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
NSRect titleRect = [self titleRectForBounds:cellFrame];
[[self attributedStringValue] drawInRect:titleRect];
}
@end
代替ソリューションが(this blogから入手される):
@implementation RSVerticallyCenteredTextFieldCell
- (NSRect)drawingRectForBounds:(NSRect)theRect
{
NSRect newRect = [super drawingRectForBounds:theRect];
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;
}
- (void)selectWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject start:(int)selStart length:(int)selLength
{
aRect = [self drawingRectForBounds:aRect];
mIsEditingOrSelecting = YES;
[super selectWithFrame:aRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength];
mIsEditingOrSelecting = NO;
}
- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent
{
aRect = [self drawingRectForBounds:aRect];
mIsEditingOrSelecting = YES;
[super editWithFrame:aRect inView:controlView editor:textObj delegate:anObject event:theEvent];
mIsEditingOrSelecting = NO;
}
@end
私は、プレゼンテーションのその部分を自分のデータレイヤーと結合する必要があります。正に、私はそれが好きであるかどうかはわかりません。これは、IBに提示された選択肢を尊重すべきであるが、何らかの理由でそうではない(垂直方向の整列もまたIBの選択肢でなければならない)。 –
NSTextFieldCellの文字列をモデルレイヤーに設定する以外に、どのように混合するのかよく分かりません。:-)整列(およびフォント、色、サイズなど)は、このすべての一部です。しかし、私は、垂直方向の調整がオプションであるべきだということに同意する - 拡張レポートを提出する。それが利用できないので、あなたはそれを描画コードで考慮する必要があります。 –
Er、それは「強化要求」です。リンク:http://bugreporter.apple.com –