¿Cómo se puede personalizar NSSLider para proporcionar una escala no lineal en cacao?

StackOverflow https://stackoverflow.com/questions/5810753

  •  25-10-2019
  •  | 
  •  

Pregunta

¿Cómo se puede personalizar NSSLider para proporcionar una escala no lineal en cacao? es decir, 0, 2, 4, 6, 10.

Con el control deslizante limitado a detenerse solo en marcas de tigas, quiero que el control deslizante se detenga en 0, 2, 4, 6, 10 (y no 8, por ejemplo). Gracias.

¿Fue útil?

Solución

Ejemplo escrito rápidamente basado en una matriz con los valores deseados:

Sampepdelegate.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

Sampepdelegate.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

Interface Builder:
- Agregar nsslider (conectar iBoutlet / Connect Ibaction / Enable Continuos Actualation)
- Agregar nstextfield (conectar iBoutlet)

Resultado:

enter image description here

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top