NSSLiderをカスタマイズして、ココアで非線形スケールを提供することができますか?
質問
NSSLiderをカスタマイズして、ココアで非線形スケールを提供することができますか? IE -0、2、4、6、10。
スライダーがティックマークのみで停止するように制約されているため、スライダーを0、2、4、6、10(たとえば8ではなく)で停止させたいと思います。ありがとう。
解決
目的の値を持つ配列に基づいて、すぐに書かれた例:
sampleappdelegate.h
#import <Cocoa/Cocoa.h>
@interface SampleAppDelegate : NSObject <NSApplicationDelegate> {
NSWindow * window;
NSArray * values;
IBOutlet NSSlider * theSlider;
IBOutlet NSTextField * theLabel;
}
- (IBAction)sliderChanged:(id)sender;
@property (assign) IBOutlet NSWindow *window;
@end
sampleappdelegate.h
#import "SampleAppDelegate.h"
@implementation SampleAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
values = [[NSArray alloc] initWithObjects:@"0",@"1",@"2",@"10",@"50",nil];
[theSlider setNumberOfTickMarks:[values count]];
[theSlider setMinValue:0];
[theSlider setMaxValue:[values count]-1];
[theSlider setAllowsTickMarkValuesOnly:YES];
[theLabel setStringValue:[values objectAtIndex:0]];
[theSlider setIntValue:0];
}
- (IBAction)sliderChanged:(id)sender {
int current = lroundf([theSlider floatValue]);
[theLabel setStringValue:[values objectAtIndex:current]];
}
@end
インターフェイスビルダー:
-NSSLIDERを追加します(IBOUTLET / CONNECT IBACTION / ENABLE CONTINUOS UPDATING)
-NSTEXTFIELDを追加(IBOUTLETを接続)
結果:
所属していません StackOverflow