nstextfield

Listen to a value change of my text field

旧巷老猫 提交于 2019-11-26 14:24:30
问题 I'm trying to understand how to catch a "text changed" event from a text field in my window. I'm used to Java's "action listeners", and can't find anything similar in Objective-C/Cocoa. I searched for quite a while and found the "key value observing" protocol, but the observeValueForKeyPath: method (function?) only triggers when the value of my text field was changed in code (using [textfield setStringValue:...] , e.g.), not by typing in it. How can I "listen" to the value change when a user

Get NSTextField contents to scale

偶尔善良 提交于 2019-11-26 13:08:35
问题 How can I have the text scale to fit the bounds I gave it? 回答1: I've done something like this in the past. -(void)calcFontSizeToFitRect:(NSRect)r { float targetWidth = r.size.width - xMargin; float targetHeight = r.size.height - yMargin; // the strategy is to start with a small font size and go larger until I'm larger than one of the target sizes int i; for (i=minFontSize; i<maxFontSize; i++) { NSDictionary* attrs = [[NSDictionary alloc] initWithObjectsAndKeys:[NSFont fontWithName

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

时光总嘲笑我的痴心妄想 提交于 2019-11-26 12:02:37
问题 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? 回答1: 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

How to make marquee UILabel / UITextField / NSTextField

心已入冬 提交于 2019-11-26 10:02:44
问题 I need to make marquee UILabel in Xcode. The marquee will scroll from right to left. I tried CCScrollingLabel also JHTickerView and others. But i can not find simple code with marquee with out any views/arrays/some stupid libraries and others How to make marquee with UILabel ? ( UITextField and NSTextField are OK too). 回答1: You need NSTimer and you need to invoke a method something as : * This is for OSX, you can easily convert it into iOS, NSTextField and UILabel has different methods. -

iTunes Song Title Scrolling in Cocoa

守給你的承諾、 提交于 2019-11-26 09:35:44
问题 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

NSTextField waits until the end of a loop to update

喜夏-厌秋 提交于 2019-11-26 07:44:05
问题 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

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

醉酒当歌 提交于 2019-11-26 07:34:24
问题 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? 回答1: 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