UITextField 在编辑时更改字体

发布于 2025-01-07 23:38:38 字数 694 浏览 3 评论 0原文

我遇到了与这里相同的问题 UITextField 的自定义字体在编辑模式下发生变化 并且确实可以找到解决方案。

我有 4 个 UITextFields,我在 ViewDidLoad 中分配自定义字体。 这很有效,而且看起来很棒,但是当单击字段编辑文本时,字体会变回默认文本,而当 resignedfirstresponder 时,自定义字体会恢复。

- (void)viewDidLoad
{
    [super viewDidLoad];
    {

        UIFont *twoDumb = [UIFont fontWithName:@"Dumb" size:20.f];

        lbl1.font = twoDumb;
        broughtForward.font = twoDumb;
        lbl2.font = [UIFont fontWithName:@"Dumb" size:24.f];
        amountTextfield.font = twoDumb;
        lbl3.font = twoDumb;

如果我使用系统字体,那么文本字段将按其应有的方式工作,因此可能与此字体文件有关?

I am suffering the same problem as here UITextField's custom font changes while in edit mode
and could really do with a solution.

I have 4 UITextFields that I assign custom fonts in ViewDidLoad.
This works and they look great, however when clicking a field to edit the text the font changes back to default text and when resignedfirstresponder the custom font comes back.

- (void)viewDidLoad
{
    [super viewDidLoad];
    {

        UIFont *twoDumb = [UIFont fontWithName:@"Dumb" size:20.f];

        lbl1.font = twoDumb;
        broughtForward.font = twoDumb;
        lbl2.font = [UIFont fontWithName:@"Dumb" size:24.f];
        amountTextfield.font = twoDumb;
        lbl3.font = twoDumb;

If I use system fonts, then the text field works as it should, so there must be something to do with this font file maybe?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

素衣风尘叹 2025-01-14 23:38:38

我发现当我在代码中的任何位置设置 UILabel 外观时:

[[UILabel appearance] setFont:MYFONT];

更改 UITextField 字体仅适用于编辑文本,而不适用于用户未编辑时文本字段中显示的文本。

I have found that when I'm setting the UILabel appearance anywhere in the code:

[[UILabel appearance] setFont:MYFONT];

Changing UITextField font only applies to editing text, and not to the text shown in textfield when user is not editing it.

黑寡妇 2025-01-14 23:38:38

我已经下载了该字体并在 iPhone 应用程序中尝试过。我还从互联网上下载了一些其他字体并尝试了它们。我还尝试了一些 Mac 字体,例如 Chalkduster。我也尝试过3Dumb。结果除了 2Dumb 和 3Dumb 之外,我尝试过的所有字体都有效。解决方案:使用其他字体。

I have downloaded that font and tried it in an iPhone app. I also downloaded some other fonts from the internet and tried them as well. I also tried some Mac fonts such as Chalkduster. I also tried 3Dumb. The results every font I tried EXCEPT 2Dumb and 3Dumb worked. Solution: Use another font.

葬﹪忆之殇 2025-01-14 23:38:38

在此处输入图像描述您使用的标签 (lbl1,lbl2,lbl3) 是自定义的还是从 xib 文件设置的?

我怀疑它正在更改的字体是由于 Xib 文件中设置的字体所致。

在此处输入图像描述

enter image description hereThe lable (lbl1,lbl2,lbl3) which you have used are custom or is it set from xib file?

I doubt the font it is changing is due to font set in Xib file.

enter image description here

勿忘初心 2025-01-14 23:38:38

编辑时可以重新设置字体,编辑时的字体是一样的。

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    textField.font = customizedFont; //The font you want to use no matter editing/no editing

}

You can set the font again when editing, the font will be the same when editing.

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    textField.font = customizedFont; //The font you want to use no matter editing/no editing

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文