• 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: Field Editor Changes Text Height [solved]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Field Editor Changes Text Height [solved]


  • Subject: Re: Field Editor Changes Text Height [solved]
  • From: "K. Darcy Otto" <email@hidden>
  • Date: Mon, 18 May 2009 16:39:13 -0700

A possible solution is to insert the following line between [fieldEd setString ... and [fieldEd setSelected ... (the two lines at the end of the code):

[fieldEd setFont:[NSFont fontWithDescriptor:[[fieldEd font] fontDescriptor] size:[[fieldEd font] pointSize]]];

This will set the font for the entire fieldEd to the same type and size as the first letter. I haven't been able to create any resizing problems with this, presumably because my resizing problem does not crop up in the first character of the field. Or at least, I haven't been able to make it crop up for the first character of the field. I suppose to be safe, you might specify the font directly:

[fieldEd setFont:[NSFont fontWithDescriptor:<fonttoforce> size:<sizetoforce>]];

On 18-May-09, at 2:46 PM, K. Darcy Otto wrote:

I need to trap-and-replace various keypresses in the field editor. I do this with -controlTextDidChange: in my delegate. So, when the user presses ">", I replace it with a "superset of" (⊃) character (in case this does not come out on the list, I'm going to represent the "superset of" character with *s*). Here is the code:

-(void)controlTextDidChange:(NSNotification *)aNotification
{
// Set fieldString to the string showing in the field editor
NSMutableString *fieldString = [NSMutableString stringWithString: [fieldEd string]];


	// Change ">" to horseshoe in fieldString
	[fieldString replaceOccurrencesOfString:@">"
	withString:[NSString stringWithFormat:@"%C",0x2283] // 0x2283 is *s*
	options:NSLiteralSearch
	range:NSMakeRange(0,[fieldString length])];

NSRange selectedRange = [fieldEd selectedRange]; // Where the cursor is before the changes
[fieldEd setString:fieldString]; // Set field editor to new string. Cursor will be set to the end of the string
[fieldEd setSelectedRange:selectedRange]; // Return cursor to where it should be
}


Now, this always makes the change. The problem is that in certain circumstances, the font height of some characters in the string, not related to the search-and-replace function, is changed. But only sometimes. For example, if I enter:

C>C ... this becomes C*ss*C just as it should.

But if I enter:

>C> ... this becomes *ss*C*ss* as it should, except the C is a half- height C. Everything else looks normal.

I also make other search-and-replaces in the -controlTextDidChange method (I've given only the basic snippet of code), some of which exhibit this problem, and others of which do not. It seems to depend on the replacement string.

Some additional background:

(1) I have "no rich text" checked for the relevant text fields in IB.
(2) If I copy-and-paste from the field editor into TextEdit, everything looks normal in all cases.
(3) When the user presses return and the text is passed to the text field, everything looks normal in all cases.


I'm not sure why it is doing this; but more importantly, I'm not sure how to fix it. Any help would be greatly appreciated._______________________________________________

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

_______________________________________________

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


References: 
 >Field Editor Changes Text Height (From: "K. Darcy Otto" <email@hidden>)

  • Prev by Date: Cancelling an animation in a UITableViewCell was Re: UITableViewCell instances
  • Next by Date: Re: Databases on Cocoa (was Re: Invoice program made in Objective c/Cocoa)
  • Previous by thread: Field Editor Changes Text Height
  • Next by thread: NSEvent virtual keycodes
  • Index(es):
    • Date
    • Thread