6
코코아에서 비선형 스케일을 제공하기 위해 NSSlider를 어떻게 사용자 정의 할 수 있습니까? 예 : 0, 2, 4, 6, 10코코아에서 비선형 규모를 제공하기 위해 NSSlider를 어떻게 사용자 정의 할 수 있습니까?
슬라이더가 눈금 표시에만 멈추도록 제한된 상태에서 슬라이더를 0, 2, 4, 6, 10 (8이 아닌 8) . 감사. 원하는 값에 기초하여 배열
코코아에서 비선형 스케일을 제공하기 위해 NSSlider를 어떻게 사용자 정의 할 수 있습니까? 예 : 0, 2, 4, 6, 10코코아에서 비선형 규모를 제공하기 위해 NSSlider를 어떻게 사용자 정의 할 수 있습니까?
슬라이더가 눈금 표시에만 멈추도록 제한된 상태에서 슬라이더를 0, 2, 4, 6, 10 (8이 아닌 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/conn 연결 요법 IBAction를 활성화/통주 업데이트는)
- NSTextField있는()가
결과를 함께 IBOutlet 연결 추가
일이 그 일의 권장되는 방법입니다. –
대단히 감사합니다. 그 접근 방식은 훌륭하게 작동했습니다. –
앤이 다시 공격합니다. 좋은 코드. :) –