nstextfield

How to limit NSTextField text length and keep it always upper case?

家住魔仙堡 提交于 2019-11-27 06:54:46
Need to have an NSTextField with a text limit of 4 characters maximum and show always in upper case but can't figure out a good way of achieving that. I've tried to do it through a binding with a validation method but the validation only gets called when the control loses first responder and that's no good. Temporarly I made it work by observing the notification NSControlTextDidChangeNotification on the text field and having it call the method: - (void)textDidChange:(NSNotification*)notification { NSTextField* textField = [notification object]; NSString* value = [textField stringValue]; if (

How to let NSTextField grow with the text in auto layout?

南楼画角 提交于 2019-11-27 06:30:12
Auto layout in Lion should make it fairly simple to let a text field (and hence a label) grow with text it holds. The text field is set to wrap in Interface Builder. What is a simple and reliable way to do this? Monolo The method intrinsicContentSize in NSView returns what the view itself thinks of as its intrinsic content size. NSTextField calculates this without considering the wraps property of its cell, so it will report the dimensions of the text if laid out in on a single line. Hence, a custom subclass of NSTextField can override this method to return a better value, such as the one

Text change notification for an NSTextField

人走茶凉 提交于 2019-11-27 05:27:51
问题 I would like to use the code from the answer to this question: How to observe the value of an NSTextField on an NSTextField in order to observe changes on the string stored in the NSTextField. [[NSNotificationCenter defaultCenter] addObserverForName:NSTextViewDidChangeSelectionNotification object:self.textView queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note){ NSLog(@"Text: %@", self.textView.textStorage.string); }]; The class used here is an NSTextView. I can't find a

Restrict NSTextField input to numeric only? NSNumberformatter

拟墨画扇 提交于 2019-11-27 04:34:29
问题 I'm just getting started up with Mac App Development and so far everything is good well, I'm just having problems trying to get a NSTextField to only accept numbers for the input. So far I have added a formatter to the NSTextField and set it to only allow decimal now when I enter letters in the field it still allows me but does not allow my to click out of the cell when done. Ideally I would like the app not to let the user type in any letters and just beep or do nothing. Any tips or pointers

getting a NSTextField to grow with the text in auto layout?

≯℡__Kan透↙ 提交于 2019-11-27 04:25:57
问题 I'm trying to get my NSTextField to have its height grow (much like in iChat or Adium) once the user types enough text to overflow the width of the control (as asked on this post) I've implimented the accepted answer yet I can't seem to get it to work. I have uploaded my attempt at http://scottyob.com/pub/autoGrowingExample.zip Ideally, when the text grows, the containing window should grow with it, but I'm trying baby steps here. 回答1: Solved it! (Inspired by https://github.com/jerrykrinock

iTunes Song Title Scrolling in Cocoa

拥有回忆 提交于 2019-11-27 01:14:04
I have searched extensively and cannot for the life of me find any information about how to achieve a similar effect to that of the iTunes song title scrolling if the text is too large in Cocoa. I have tried setting the bounds on a NSTextField to no avail. I have tried using NSTextView as well as various attempts at using NSScrollView. I am sure I am missing something simple but any help would be greatly appreciated. I am also hoping to not have to use CoreGraphics if at all possible. Example , notice the "Base.FM http://www ." text has been scrolled. If you need a better example open iTunes

Color attribute is ignored in NSAttributedString with NSLinkAttributeName

荒凉一梦 提交于 2019-11-26 21:47:53
问题 In an NSAttributedString , a range of letters has a link attribute and a custom color attribute. In Xcode 7 with Swift 2, it works: In Xcode 8 with Swift 3, the custom attributed color for the link is always ignored (it should be orange in the screenshot). Here's the code for testing. Swift 2, Xcode 7: import Cocoa import XCPlayground let text = "Hey @user!" let attr = NSMutableAttributedString(string: text) let range = NSRange(location: 4, length: 5) attr.addAttribute

NSTextField waits until the end of a loop to update

筅森魡賤 提交于 2019-11-26 20:44:32
Here's the problem: I have some code that goes like this otherWinController = [[NotificationWindowController alloc] init]; for (int i = 0; i < 10; i++) { [otherWinController showMessage:[NSString stringWithFormat:@"%d", i]]; NSLog(@"%d", i); sleep(1); } where otherWinController is a subclass of NSWindowController that I am using to update my window as changes happen in code, and the alloc init method simply opens up the nib and shows the window. showMessage is a method that changes an NSTextView to display whatever text is in the parameter. in the NSLog, the text changes every second and just

Not being able to edit NSTextField on NSPopover even though Editable behavior is set

∥☆過路亽.° 提交于 2019-11-26 20:22:14
I have an application, which open popover with NSTextField . The text field is not editable. Behavior for text field is set to Editable . I still can paste and copy text to this field but i can't edit it. Anyone knows, what can be wrong? Balazs Toth Not sure if you still need the answer, but there may be some others still looking. I found a solution on apple developer forums. Quoting the original author: The main problem is the way keyboard events works. Although the NSTextField (and all its superviews) receives keyboard events, it doesn't make any action. That happens because the view where

Which delegate method should I use to respond to clicks on an NSTextField?

谁说我不能喝 提交于 2019-11-26 16:47:52
问题 I am trying to respond to a click within a textfield . When the click occurs, I am going to open a panel . My initial thought was to use a delegate method to respond to the click event - but I found that: This method doesn't work: (void)textDidBeginEditing:(NSNotification *)aNotification This method does work, but only when I actually edit the text within the text field, not when I first click it. And - if I edit the text a second time, this method stops working: (void