nstextfield

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

一曲冷凌霜 提交于 2019-11-27 20:15:12
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. Solved it! (Inspired by https://github.com/jerrykrinock/CategoriesObjC/blob/master/NS(Attributed)String%2BGeometrics/NS(Attributed)String%2BGeometrics.m ) Reading

Can't change the mouse cursor of a NSTextField

我只是一个虾纸丫 提交于 2019-11-27 18:54:48
问题 I'm trying to change the mouse cursor of a NSTextField in a window sheet, loaded from a NIB. Following the documentation, I have subclassed NSTextField and implemented resetCursorRects. - (void) resetCursorRects { [self addCursorRect:[self bounds] cursor:[NSCursor pointingHandCursor]]; } This is never called. Not even after adding the following in the NSWindowViewController : - (void) windowDidLoad { [self.window invalidateCursorRectsForView:self.linkTextField]; } I also tried with a tracking

Respond to mouse events in text field in view-based table view

独自空忆成欢 提交于 2019-11-27 18:22:31
I have text fields inside a custom view inside an NSOutlineView . Editing one of these cells requires a single click, a pause, and another single click. The first single click selects the table view row, and the second single click draws the cursor in the field. Double-clicking the cell, which lets you edit in a cell-based table view, only selects the row. The behavior I want: one click to change the selection and edit. What do I need to override to obtain this behavior? I've read some other posts: The NSTextField flyweight pattern wouldn't seem to apply to view-based table views, where the

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

孤者浪人 提交于 2019-11-27 14:52:22
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)controlTextDidBeginEditing:(NSNotification *)aNotification I could use as much detail as possible - or a code example, ideally

NSTextField - White text on black background, but black cursor

℡╲_俬逩灬. 提交于 2019-11-27 13:47:45
问题 I've setup an NSTextField with text color as white, and the background color as (black despite not rendering the background color, so its transparent). All in Interface Builder. The problem I am having is the cursor is black, and hardly visible . Does the cursor not represent the text color? Any ideas how I can fix this? Otherwise, the NSTextField looks like it cannot be edited. 回答1: Your best bet is probably to use NSTextView and - (void)setInsertionPointColor:(NSColor *)color . 回答2: Since

How to make marquee UILabel / UITextField / NSTextField

半腔热情 提交于 2019-11-27 13:27:48
问题 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. -

Get value from NSTextField

十年热恋 提交于 2019-11-27 09:48:20
问题 I have an NSTextField and I need to get the field's value into a variable. What's the appropriate method? 回答1: For an NSString you would use: NSString *myString = [theTextField stringValue]; For an int you would use: int myInt = [theTextField intValue]; There are many other methods for getting the value from a control. Have a look at the NSControl reference for more info, under the "Getting and Setting the Control’s Value" section. Here's a list: doubleValue floatValue intValue integerValue

Listen to a value change of my text field

落爺英雄遲暮 提交于 2019-11-27 08:53:45
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 types in the text field? You can set a delegate for your NSTextField instance and have the delegate

Swift: Trying to update NSTextField in a loop, but it only gets the last value

此生再无相见时 提交于 2019-11-27 08:16:13
问题 My very simple program is looping through an array to export several files. While it's in the loop, I'd like it to update a text field to tell the user which file is currently exporting. Code looks like this: for item in filesArray { var fileName = item["fileName"] fileNameExportLabel.stringValue = "Exporting \(fileName).ext" println("Exporting \(fileName).ext") //--code to save the stuff goes here-- } What happens is: println works correctly, throwing out a message for each file, but the

Get NSTextField contents to scale

非 Y 不嫁゛ 提交于 2019-11-27 07:20:50
How can I have the text scale to fit the bounds I gave it? 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:currentFontName size:i], NSFontAttributeName, nil]; NSSize strSize = [string sizeWithAttributes:attrs]; [attrs release]