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
Access Each Header and Controls in The Tableview in Swift
Filter, Closure, Functional Syntax Version of for Loop with Multiple Conditions
Dealing with Octal Numbers in Swift
Xcode 9.3 Watchkit Crash on Wkinterfacebutton Tap
Add Catextlayer on Top of Nsimageview
Communicate Data Between Watchos & Today Extension Widget
Bool.Hashvalue Valid to Convert to Int
Swift Combine: Turn a Publisher into a Read-Only Currentvaluesubject
Alamofire Request Not Working in Swift 4 Project
Swift: Get The Compile Time Name of Variable (Referencing to a Class)
Open View Controller When Remote Notification Pressed
Error Validating Cms Signature
Pie Chart Entries Outside Slices Have Different Position Offsets
How to Get Address in English Language Only Using Gmsgeocoder
Adding Constraints Programmatically in UIview with UItextview
Skease Action, How to Use Float Changing Action Setter Block