Changing the height of a NSTextField for editing
Changing the height of a NSTextField for editing
- Subject: Changing the height of a NSTextField for editing
- From: Eric Gorr <email@hidden>
- Date: Mon, 23 Feb 2009 12:52:59 -0500
Here's a sample application demonstrating the problem:
http://ericgorr.net/cocoadev/label/ItemDevLabel.zip
When I click in the label, I start an editing session. However, the
height of the label can contain two lines of text. When the editing
session begins, I would like just a single line of editable text.
I begin editing by doing the following:
[textField selectText:nil];
NSTextView *currentEditor = (NSTextView*)[textField currentEditor];
NSPoint windowLocation = [theEvent locationInWindow];
NSPoint screenLocation = [[self window]
convertBaseToScreen:windowLocation];
NSUInteger characterIndex = [currentEditor
characterIndexForPoint:screenLocation];
[currentEditor setSelectedRange:NSMakeRange( characterIndex + 1,
0 )];
So, I figured I could simply take currentEditor and change it's height:
NSRect editorBounds = [currentEditor bounds];
NSSize newEditorSize = editorBounds.size;
newEditorSize.height = 16; // just some smaller value for now
[currentEditor setBoundsSize:newEditorSize];
Unfortunately, that does not work. I find it very odd that the height
of the control remains the same and the text becomes larger.
Next, I tried altering the height of textField before I started the
editing session and did:
NSSize textViewSize = [textView bounds].size;
textViewSize.height = 16;
[textView setBoundsSize:textViewSize];
However, I saw the same behavior as demonstrated in the sample
application.
Eventually, I would like to allow the user to edit on multiple lines,
but if I cannot change the height to just a single line, I have no
expectation that I'd be able to change the height to hold multiple
lines.
Anyone have any ideas?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden