nstextfield

-[NSTextField intrinsicContentSize] always has undefined width

给你一囗甜甜゛ 提交于 2020-01-21 11:25:28
问题 I'm pulling hairs here. I have an NSTextField created on a xib that has an intrinsicContentSize adjusted to it's stringValue. If I create a textField programmatically like so: _textfield = [[NSTextField alloc] initWithFrame:CGRectZero]; _textfield.translatesAutoresizingMaskIntoConstraints = NO; _textfield.alignment = NSCenterTextAlignment; _textfield.drawsBackground = NO; [_textfield setBordered:NO]; _textfiled.stringValue = @"Test" It's intrinsicContentSize is always (width=-1, height=16) I

NSTextField unrecognized selectors

一曲冷凌霜 提交于 2020-01-07 06:47:09
问题 I have a text label declared as: @property (weak) IBOutlet NSTextField *label; I set some attributes in awakeFromNib method: - (void)awakeFromNib { [label setStringValue:@"hello"]; } And it all works. But when I try to change the string value (with setStringValue as well) somewhere else in the code I receive this error: -[__NSCFString setStringValue:]: unrecognized selector sent to instance 0x105703040 I noticed it behaves the same way also with methods like isHidden, setHidden Any idea why?

Changing the Value of NSTextField doesn't update label?

感情迁移 提交于 2020-01-06 07:32:47
问题 I'm trying to change a label from the AppDelegate . I can change the label with an IBAction that runs a changeLabel in the implementation of the class that has the label, but if I try to run changeLabel from the AppDelegate it changes the value (I have an NSLog), but doesn't update label. Here's the code: #import <Foundation/Foundation.h> @interface testLabelThingy : NSObject @property (strong) IBOutlet NSTextField *daLabel; - (id) init; - (void)changeLabel; - (IBAction)daButton:(id)sender;

Update property bound from text field without needing to press Enter

孤街醉人 提交于 2020-01-05 07:17:08
问题 I have a text field and I bind it to an NSString instance variable. When I type in the text field, it does not update the variable. It waits until I press the Enter key. I don't want to hit Enter every time. What do I need to change in order to make the binding change value immediately? 回答1: By default, the value binding of an NSTextField does not update continuously. To fix this, you need, after selecting your text field, to check the "Continuously Updates Value" box in the Bindings

NSTextField with auto-suggestions like Safari's address bar?

不打扰是莪最后的温柔 提交于 2020-01-03 10:45:48
问题 What's the easiest way to have an NSTextField with a "recommendation list" dynamically shown below it as the user types? Just like Safari's address bar that has a menu of some sorts (I'm pretty confident Safari's address bar suggestions is menu since it has rounded corners, blue gradient selection, and background blurring). I've tried using NSTextView's autocompletion facility but found it was inadequate: It tries to complete words instead of the whole text fields – in other words, selecting

Highlight a selection in NSTextField

扶醉桌前 提交于 2020-01-02 16:16:05
问题 I want to be able to highlight a portion of text in an NSTextField but I've not been able to Google a way of doing this. I have defined an NSRange but I cannot find a way of using this range to highlight the text. The only thing I have turned up is textField.selectText but this supposedly highlights the whole field. I'm using Swift 2. 回答1: You may have noticed that an NSTextField only shows a selection range when it has focus, i.e., is the first responder. In this case, editing is handled by

how to detect double Click in NSTextField

怎甘沉沦 提交于 2020-01-01 17:03:33
问题 I have a custom NSTextField and I'd like to detect double clicks by the user in the text field. My goal: I want to be able to double click on a parenthesis in an expression, such as "(2+2) = 4" and have it select everything inside the matching parentheses. Thought I could do this with... - (void)textView:(NSTextView *)textView doubleClickedOnCell:(id <NSTextAttachmentCell>)cell inRect:(NSRect)cellFrame atIndex:(NSUInteger)charIndex; but it never gets called in my custom NSTextField. Then I

Disable/Enable NSButton if NSTextfield is empty or not

瘦欲@ 提交于 2020-01-01 02:29:10
问题 I´m newbie with cocoa. I have a button and a textField in my app. I want the button disabled when the textfield is empty and enabled when the user type something. Any point to start? Any "magic" binding in Interface Builder? Thanks [EDITED] I´ve tried to set the appDelegate as the NSTextfield´s delegate and added this method (myTextfield and myButton are IBOutlets): - (void)textDidChange:(NSNotification *)aNotification { if ([[myTextField stringValue]length]>0) { [myButton setEnabled: YES]; }

Truncate beginning of label

时光毁灭记忆、已成空白 提交于 2019-12-31 04:50:09
问题 I have a label ( NSTextField ) with text aligned right. When the text becomes too large to display, the end of the text is truncated (at the right edge of the label). In my case I would actually want to truncate the beginning of the text. How can I achieve this in the Interface Builder or in code? Now | This sentence is to | Desired | entence is too long | 回答1: I'm not quite sure if this works for NSTextFields, I know it does for UILabels, but have you tried : myTextField.lineBreakMode =

NSTextFieldCell's cellSizeForBounds: doesn't match wrapping behavior?

懵懂的女人 提交于 2019-12-30 13:55:43
问题 It seems to be commonly accepted that cellSizeForBounds: allows one to calculate a text field's "natural" size. However, for NSTextField, I've found that it doesn't quite match: @interface MyTextField : NSTextField @end @implementation MyTextField - (void)textDidChange:(NSNotification *)notification { [super textDidChange:notification]; [self validateEditing]; // Forces updating from the field editor NSSize cellSize = [self.cell cellSizeForBounds: NSMakeRect(0, 0, self.bounds.size.width,