Ric Levy
Ric Levy

Reputation: 996

Why does the font of my UITextField change when editing?

My UITextField's font gets lighter when it is being edited, and bolder whenever editing finishes. These images should illustrate the problem:

Editing Not Editing

Can anyone explain why this is, and how to stop it?

This is all the code I've got for it - first my UITextField subclass (which is just there to add margins):

@interface RLTextField : UITextField {    
}
@end

@implementation RLTextField

- (CGRect)editingRectForBounds:(CGRect)bounds
{
    CGRect editingRect = CGRectMake(bounds.origin.x+35, bounds.origin.y-5, bounds.size.width, bounds.size.height);
    return editingRect;
}

- (CGRect)textRectForBounds:(CGRect)bounds
{
    CGRect editingRect = CGRectMake(bounds.origin.x+35, bounds.origin.y-5, bounds.size.width, bounds.size.height);
    return editingRect;
}
@end

And then where it's actually added in my viewController:

- (void)viewDidLoad
{   
    CGRect noteTitleTextFrame  = CGRectMake(self.view.bounds.origin.x, 
                                            self.view.bounds.origin.y+10, 
                                            self.view.bounds.size.width, 
                                            44);
    RLTextField *textField = [[RLTextField alloc] initWithFrame:noteTitleTextFrame];
    self.nameTextField = textField; [textField release];
    self.nameTextField.delegate = self;
    self.nameTextField.borderStyle = UITextBorderStyleNone;    
    self.nameTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;
    self.nameTextField.font = [UIFont fontWithName:@"Courier" size:21];
    [self.view addSubview:self.nameTextField]; 
}

Upvotes: 4

Views: 2576

Answers (1)

Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 39978

checked your code.... and there only one word for that WTF....!
I don't know what's wrong with that but there is a solution for that and it's

self.nameTextField.font = [UIFont fontWithName:@"Courier New" size:21];


just change the font name. This will work.. cheers :)
By the way you probably found a bug or may be not that's why apple has added "Courier New".
I don't know...

Upvotes: 4

Related Questions