UITextField 在编辑时更改字体
我遇到了与这里相同的问题 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我发现当我在代码中的任何位置设置 UILabel 外观时:
更改
UITextField
字体仅适用于编辑文本,而不适用于用户未编辑时文本字段中显示的文本。I have found that when I'm setting the UILabel appearance anywhere in the code:
Changing
UITextField
font only applies to editing text, and not to the text shown in textfield when user is not editing it.我已经下载了该字体并在 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.
我怀疑它正在更改的字体是由于 Xib 文件中设置的字体所致。
I doubt the font it is changing is due to font set in Xib file.
编辑时可以重新设置字体,编辑时的字体是一样的。
You can set the font again when editing, the font will be the same when editing.