我試圖圍繞NSTextField繪製圓角。帶圓角的NSTextField?
我子類NSTextField
,嘗試下面的代碼,但沒有任何結果......
任何想法?
- (void)drawRect:(NSRect)dirtyRect
{
// black outline
NSRect blackOutlineFrame = NSMakeRect(0.0, 0.0, [self bounds].size.width, [self bounds].size.height-1.0);
NSGradient *gradient = nil;
if ([NSApp isActive]) {
gradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedWhite:0.24 alpha:1.0] endingColor:[NSColor colorWithCalibratedWhite:0.374 alpha:1.0]];
}
else {
gradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithCalibratedWhite:0.55 alpha:1.0] endingColor:[NSColor colorWithCalibratedWhite:0.558 alpha:1.0]];
}
[gradient drawInBezierPath:[NSBezierPath bezierPathWithRoundedRect:blackOutlineFrame xRadius:5 yRadius:5] angle:90];
}
嗯...它不適合我... – 2012-03-29 21:22:24
嗯,我剛剛發現有什麼問題......我在創建文本字段實例時設置了一個'setBackgroundColor:',然後是'setDrawsBackground:YES'。現在,當我刪除它,它的作品!但是:如果在'setBezelStyle:'之後添加背景,背景保持白色......任何建議? – 2012-03-29 21:27:31
@ Dr.Kameleon當用戶點擊textField時,你想要改變背景顏色嗎?而firstResponder?如果不是那種顏色,不要顯示這種顏色? – 2012-03-29 22:27:15