UITextField custom font changes in edit mode

I have a UITextField that loads from xib. In it, we consider the methods of the viewDidLoad controllers, I set the font to a user-defined value, which is configured correctly in the .plist file and that’s it. It displays perfectly, except when it is in edit mode, after which the font switches from my custom font to the default font, which, it seems to me, is Helvetica . This is annoying, and I would like to keep my own font everywhere. I looked around and I do not see an immediate solution, the only thing I tried was to reset the textField.font property in the delegate methods textFieldShouldBeginEditing and textFieldDidBeginEditing , nothing about anything.

Edit: I was asked to enter the code, in fact this is only one line, but here.

  - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. self.myTextField.font = [UIFont fontWithName:@"MyFont" size:18]; } 

I also tried resetting the font in two ways:

  -(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 when editing, but then returns back to the custom font after the keyboard is rejected.

Second edit:

Well, I just did what I probably should have tried before, and used several different font files. Both of these fonts worked fine, but for some reason the custom font file I used causes a problem, even though it works fine in all other situations.

+3
ios objective-c iphone
source share
3 answers

I had this problem with the otf font (in fact, I always had problems with otf fonts ...), so now I only use ttf fonts that work fine. Check out this font converter website if you need to convert fonts from otf.

+1
source share

Try the following:

 - (void)textFieldDidChange:(UITextField *)textField { textField.font = [UIFont fontWithName:@"MyFont" size:18]; } 

Or, as an alternative to fhat, create an IBAction, connect it to the text field with editing the changed and add this code to your .m:

 - (IBAction)textFieldEditingChanged:(id)sender { textField.font = [UIFont fontWithName:@"MyFont" size:18]; } 
0
source share

From my experience, the problem is with the font file. I found that the only solution was to find an alternative font and switch.

0
source share

All Articles