开发者

Why does the font of my UITextField change when editing?

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

Why does the font of my UITextField change when editing?

Why does the font of my UITextField change when 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]; 
}


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜