2011-01-13 47 views

回答

5

你可以只繼承NSTextField和覆蓋-drawRect:方法來「填充」整個寬度與進步一些顏色或漸變(或其他)的合適比例。如果我正確理解你的問題。

-(void)drawRect:(NSRect)dirtyRect { 
    CGFloat progress = 0.33; 

    NSRect progressRect = [self bounds]; 
    progressRect.size.width *= progress; 

    [[NSColor colorWithCalibratedRed:0.0 green:0.0 blue:1.0 alpha:0.4] set]; 
    NSRectFillUsingOperation(progressRect, NSCompositeSourceOver); 

    [super drawRect:dirtyRect]; 
} 

很明顯,「進度」來自您聲明的屬性並根據模型進行更新。您需要確保setDrawsBackground:處於關閉狀態,或者背景設置爲[NSColor clearColor];才能看到自定義繪圖。

這是上面代碼的一個鏡頭。

Tested Theory