• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Changing the height of a NSTextField for editing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Changing the height of a NSTextField for editing


  • Subject: Re: Changing the height of a NSTextField for editing
  • From: Nate Weaver <email@hidden>
  • Date: Mon, 23 Feb 2009 16:14:02 -0600

Try setting the frame of the field/field editor instead (doing unit conversions if necessary). When you change the bounds of something explicitly, you end up changing the drawing transformation as well (see under setBounds: and friends).

This has bitten me in the butt before (recently!).

HTH!


On Feb 23, 2009, at 11:52 AM, Eric Gorr wrote:

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


  • Follow-Ups:
    • Re: Changing the height of a NSTextField for editing
      • From: Eric Gorr <email@hidden>
References: 
 >Changing the height of a NSTextField for editing (From: Eric Gorr <email@hidden>)

  • Prev by Date: Getting CGImage out of NSBitmapImageRep in 10.4
  • Next by Date: Re: Moving oneself to /Applications (or ~/Applications)
  • Previous by thread: Changing the height of a NSTextField for editing
  • Next by thread: Re: Changing the height of a NSTextField for editing
  • Index(es):
    • Date
    • Thread