解決策1:
私が考えることができる最も簡単な解決策は、お互いに2つのテキストを書くことである(例えば、頂部及び底部における差分1ピクセルと白に灰色)。
解決方法2:
そしてもちろん、それはNSTextFieldCell
をサブクラス化し、影を追加することによって行うことができます。ただ、このような
:
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
NSShadow *shadow = [[NSShadow alloc] init];
[shadow setShadowOffset:NSMakeSize(0,-1)];
[shadow setShadowColor:[NSColor whiteColor]];
[shadow setShadowBlurRadius:0];
NSMutableParagraphStyle *paragStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[paragStyle setAlignment:[self alignment]];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[self font],NSFontAttributeName,
shadow,NSShadowAttributeName,
[self textColor],NSForegroundColorAttributeName,
paragStyle,NSParagraphStyleAttributeName,nil];
[shadow release];
[paragStyle release];
NSAttributedString *string = [[NSAttributedString alloc] initWithString:[self stringValue] attributes:attributes];
[self setAttributedStringValue:string];
[string release];
[[self attributedStringValue] drawInRect:cellFrame];
}
結果:
![Text example](https://i.stack.imgur.com/BrBwi.png)