nstextfield

Make NSTextField update its bound value when setting its string value programmatically

喜欢而已 提交于 2019-12-25 04:11:34
问题 I have an NSTextField bound to a key in the user defaults. When I press enter or leave the field the bound value is properly updated (I have an observer for it). However when I programmatically set the value of the text field the bound value is not updated. The text field however shows the new string I set with: stockField1.stringValue = [sender representedObject]; (it's set from a menu item handler). Is it necessary to send an additional message to the text field or how else can I make this

CALayer and drawRect

£可爱£侵袭症+ 提交于 2019-12-24 10:27:42
问题 I'm completely new to Core Animation, CALayer and all this stuff, so bear with me. I have a custom NSTextField using as a Label. I would want the content to animate it's position, so the whole string get's visible if it's too long for the Labels width. Now, the animation itself is working fine. I've implemented this with CABasicAnimation: - (void)awakeFromNib { CALayer *newLayer = [CALayer layer]; CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"]; [animation

NSTextField captures return key event twice

橙三吉。 提交于 2019-12-24 10:05:05
问题 I have a textfield and two buttons. The user should be able to press return when they’re done editing the textfield, and then return again to activate one or the other of the buttons, depending on conditions. In order to make it clear to the user that they can return to activate the button, I temporarily assign return as the chosen button’s key equivalent, which should make it glow blue. The textfield’s sent-action selector includes this code: switch (self.iNavMode) { case kNavModeNeutral:

No input to NSTextField when running macruby

陌路散爱 提交于 2019-12-24 00:47:17
问题 i have a simple macruby application and i want to get some user-input via a NSTextField, but when i run the application with '''macruby test.rb''' all the input on the focused text-field goes into the bash. is there something that i need to set, to get the input into the text-field? # test.rb framework 'AppKit' application = NSApplication.sharedApplication frame = [0.0, 0.0, 300, 200] window = NSWindow.alloc.initWithContentRect(frame, styleMask: NSTitledWindowMask | NSClosableWindowMask,

NSTextField margin and padding? (Swift)

試著忘記壹切 提交于 2019-12-23 17:27:05
问题 I am wondering if there’s a possibility to set a margin or padding for NSTextField ? I achieved a more or less custom looking textField (the first one in this screenshot)... ... using this code: myTextField.wantsLayer = true myTextField.layer?.cornerRadius = 2.0 myTextField.layer?.borderWidth = 1.0 myTextField.layer?.borderColor = CGColor(red: 0.69, green: 0.69, blue: 0.69, alpha: 1.0) However, it feels like I have to add some padding on the left side so that the numbers are not too close to

How to check if NSTextfield is already truncating the text (… at the end)

核能气质少年 提交于 2019-12-23 09:02:02
问题 I've searched around on how to perform this but I can't find any answer. I'd like to know if my NSTextfield is already truncating the text (... at the end) without having to check the length of its stringValue . I need to do this to know if I should set a tooltip on my NSTextfield (acting like a simple label). The reason I don't want to check the length of my textfield's stringValue it's because there are some characters that occupy more space than others, so that's not very accurate Thanks!

NSTextField non-system-font content clipped when usesSingleLineMode is true

心已入冬 提交于 2019-12-23 08:48:59
问题 Setting usesSingleLineMode to true for a non-system font causes the top of the text to be clipped. I've created 3 very simple test cases that illustrate this: good : non-system font, with usesSingleLineMode = false. Works fine. bad : non-system font with usesSingleLineMode = true. Does not work. system : system font with usesSingleLineMode = true. Works fine. Add the following to the viewDidLoad() method of a new Cocoa OSX application: // Do any additional setup after loading the view. let

Swift: How to continuously send an action from a NSTextField

隐身守侯 提交于 2019-12-23 04:43:46
问题 I have a NSTextField and want to send an action whenever the user changes the value. I checked "Continuous" in the Interface Builder (which works i.e. fine with NSSlider), but the NSTextField only sends his action if I unfocus it. How can I continuously send an action from a NSTextField (using Swift)? 回答1: Set the delegate of the text field to the class which is supposed to receive the action and implement func controlTextDidChange(_ obj: NSNotification) This method is invoked when text in a

KVO causes loop if observers to other objects are not removed

可紊 提交于 2019-12-23 03:16:05
问题 I have observers added to several NSTextFields to monitor changes in each text field. The key of each text field is configured in Interface Builder at Bindings -> Value -> Model Key Path . When the number in one text field is changed, the other text fields automatically update their value. Since an observer was added to each text field, I must remove the other observers to avoid a loop that will crash the app. After the observers are removed, I must add them back to the other text fields so

KVO causes loop if observers to other objects are not removed

家住魔仙堡 提交于 2019-12-23 03:16:00
问题 I have observers added to several NSTextFields to monitor changes in each text field. The key of each text field is configured in Interface Builder at Bindings -> Value -> Model Key Path . When the number in one text field is changed, the other text fields automatically update their value. Since an observer was added to each text field, I must remove the other observers to avoid a loop that will crash the app. After the observers are removed, I must add them back to the other text fields so