Way to Check If Up or Down Button Is Pressed with Nsstepper

Integrate NSStepper with NSTextField

Skip the takeIntValueFrom: method. Instead, bind both views to the same property in your controller. You may also want to create a formatter and hook up the text field's formatter outlet to it.

UIStepper - Find out whether it is incremented or decremented

So I thought about a subclass for this. It turns out to be not so bad (except for wrapped values).

Using the subclass

- (IBAction)stepperOneChanged:(UIStepper*)stepperOne
{
if (stepperOne.plusMinusState == JLTStepperPlus) {
// Plus button pressed
}
else if (stepperOne.plusMinusState == JLTStepperMinus) {
// Minus button pressed
} else {
// Shouldn't happen unless value is set programmatically.
}
}

JLTStepper.h

#import <UIKit/UIKit.h>

typedef enum JLTStepperPlusMinusState_ {
JLTStepperMinus = -1,
JLTStepperPlus = 1,
JLTStepperUnset = 0
} JLTStepperPlusMinusState;

@interface JLTStepper : UIStepper
@property (nonatomic) JLTStepperPlusMinusState plusMinusState;
@end

JLTStepper.m

#import "JLTStepper.h"

@implementation JLTStepper
- (void)setValue:(double)value
{
BOOL isPlus = self.value < value;
BOOL isMinus = self.value > value;

if (self.wraps) { // Handing wrapped values is tricky
if (self.value > self.maximumValue - self.stepValue) {
isPlus = value < self.minimumValue + self.stepValue;
isMinus = isMinus && !isPlus;
} else if (self.value < self.minimumValue + self.stepValue) {
isMinus = value > self.maximumValue - self.stepValue;
isPlus = isPlus && !isMinus;
}
}

if (isPlus)
self.plusMinusState = JLTStepperPlus;
else if (isMinus)
self.plusMinusState = JLTStepperMinus;

[super setValue:value];
}
@end

Is there a way to add the mouse event to an Action in Interface Builder?

You can use CGEventSourceKeyState to detect whether the specific key is pressed currently or not .

And you can find the exact number for control in this link .

It should be 0x3B .

Check the code used in Xamarin below

partial void myStepperAction(Foundation.NSObject sender) {
var stepper = sender as NSStepper;

bool isCtrlPressed = CGEventSource.GetKeyState(0,0x3b);
var value = isCtrlPressed ? stepper.DoubleValue + 10 : stepper.DoubleValue;

}

NSStepper ignores current NSTextField value

Text fields and sliders are both in the view layer of the MVC pattern. You'll have much better results by binding both of those views to a property of your controller.

incrementing and decrementing stepper in swift

compare the length of your array to sender.value in stepper changed function

NSTabView with background color

PSMTabBarControl is probably the best workaround for you. I have created several custom tab views, but cocoa does not play well with this control. PSMTabBarControl has been updated to support Xcode 4. https://github.com/ciaran/psmtabbarcontrol



Related Topics



Leave a reply



Submit