在编辑模式下,UITextField的自定义字体会更改 [英] UITextField's custom font changes while in edit mode

查看:85
本文介绍了在编辑模式下,UITextField的自定义字体会更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从xib加载的 UITextField .在视图控制器的 viewDidLoad 方法中,我将字体设置为自定义值,该值在 .plist文件和所有内容中均已正确设置.除了处于编辑模式时,它显示正常,这时字体从我的自定义字体切换到默认字体,我相信它是 Helvetica .这很刺耳,我想始终保留自定义字体.我环顾四周,没有任何立即解决方案,我尝试过的唯一事情是重置 textFieldShouldBeginEditing textFieldDidBeginEditing 委托方法中的textField.font属性.,但两者都没有做任何事情.

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.

我被要求输入代码,它实际上只有一行,但是就行了.

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.

第二次修改:

好吧,我只是做了一些我以前应该尝试过的事情,并使用了几个不同的字体文件.这两种字体都可以正常工作,但是无论出于何种原因,尽管我的自定义字体文件在所有其他情况下都可以正常工作,但还是导致了该问题.

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.

推荐答案

我在使用otf字体时遇到了这个问题(实际上我在使用otf字体时一直遇到问题...),所以现在我只使用ttf字体,工作很棒.如果您需要从otf转换字体,请查看此字体转换器网站.

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.

这篇关于在编辑模式下,UITextField的自定义字体会更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆