NSSearchField
背景色を設定したいカスタムサブクラスがあります。
@interface CustomNSSearchField : NSSearchField
@end
これまでのところ、私は試しました:
試み #1
@implementation CustomNSSearchField
- (void)drawRect:(NSRect)rect
{
[super drawRect:rect];
[self setDrawsBackground:YES];
[self setBackgroundColor:[NSColor redColor]];
}
視覚的な変化はまったくありませんでした:
次に、ここでの提案に従い、次のことも試しました。
試み #2
- (void)drawRect:(NSRect)rect
{
[super drawRect:rect];
[[NSColor redColor] setFill];
NSRectFill(rect);
}
これにより、次のようになります。
検索フィールドの境界内およびテキストの背後に背景色を設定するにはどうすればよいですか?