Reputation: 31
I have a UITextField
that is loaded from a xib. In it's view controllers viewDidLoad
method, I set the font to a custom value which is set up correct in the .plist file
and everything. It displays fine except for when it is in edit mode, at which point the font switches from my custom font to the default font, which I believe is Helvetica
. This is jarring, and I'd like to keep the custom font throughout. I've looked around and I don't see any immediate solution, the only thing I've tried is resetting the textField.font property in the textFieldShouldBeginEditing
and textFieldDidBeginEditing
delegate methods, neither of which did anything.
Edit: I've been asked for the code, it really only is one line but here goes.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.myTextField.font = [UIFont fontWithName:@"MyFont" size:18];
}
I've also tried resetting the font in the following two methods:
-(void)textFieldDidBeginEditing:(UITextField *)textField
{
textField.font = [UIFont fontWithName:@"MyFont" size:18];
}
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
textField.font = [UIFont fontWithName:@"MyFont" size:18];
return YES;
}
This does nothing, the font still changes while editing takes place, but then changes back to the custom font once the keyboard is dismissed.
Second edit:
Well, I just did something I probably should have tried before, and used a couple of different font files. Both of those fonts worked fine, but for whatever reason the custom font file I was using is causing the problem, despite it working normally in all other situations.
Upvotes: 3
Views: 3711
Reputation: 4164
I had this problem with an otf font (in fact I've always had problems with otf fonts...) so now I use only ttf fonts, which work great. Check out this font converter website if you need to convert fonts from otf.
Upvotes: 1
Reputation: 484
From my experience, the problem is with the font file. I found that the only solution was to find an alternative font and switch.
Upvotes: 0
Reputation: 9324
Try this:
- (void)textFieldDidChange:(UITextField *)textField {
textField.font = [UIFont fontWithName:@"MyFont" size:18];
}
Or as an alternative to fhat create an IBAction, connect it to the textField with Editing Changed and add this code to your .m:
- (IBAction)textFieldEditingChanged:(id)sender {
textField.font = [UIFont fontWithName:@"MyFont" size:18];
}
Upvotes: 0