UITextField中的文本在编辑后向上移动(编辑时居中) [英] Text in UITextField moves up after editing (center while editing)

查看:110
本文介绍了UITextField中的文本在编辑后向上移动(编辑时居中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题。我有一个UITextField,用户应在其中写入一些内容,因此该字段称为amountField。一切都很好看,当用户开始编辑文本字段时,文本位于垂直和水平中心 - 这很棒。

I have a strange problem. I have an UITextField in which the user should write the amount of something, so the field is called "amountField". Everything looks fine, when the user starts editing the textfield the text is in the vertical and horizontal center - that's great.

但是,当用户结束编辑时,文字会向上移动一点点。我尝试了很多东西,没什么帮助...

However, when the user ends editing the text moves up a little bit. I tried many things, nothing helped...

我在下面添加截图,这样你就可以看出问题所在。

I am adding screenshots below, so you can see what is the problem.

这是编辑字段时的样子 - 没关系。

This is what it looks like while editing the field - that's ok.

这就是完成编辑后的样子 - 即问题

And this is how it looks when done editing - that is the problem!

如果有人知道可能导致这种情况的原因,我将非常感激! :)

Please, if anybody know what could cause this I would be very grateful! :)

这是我的一些与amountField相关的代码。

Here is some of my code related to the amountField.

amountField.keyboardType = UIKeyboardTypeNumberPad;
amountField.returnKeyType = UIReturnKeyDone;
amountField.delegate = self;

[amountField setFont:[UIFont fontWithName:@"Nuptial Script LT Std" size:30]];   
amountField.borderStyle = UITextBorderStyleNone;
UIImage *amountBg = [UIImage imageNamed:@"skin2_ipad_amountField.png"];
[amountField setBackground:amountBg];

amountField.rightView = nil;
//amountField.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.2];

amountField.textAlignment = UITextAlignmentCenter;
amountField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
amountField.adjustsFontSizeToFitWidth = YES;
amountLabel.textColor = UIColorFromARGB(0x313030); //Using my own macro

amountField.frame = CGRectMake(300, 480, 136, 32);
amountField.center = CGPointMake(605, 439);

PS:那些白色角落是因为我将背景设置为白色,带有0.2 alpha,这没关系。

PS: Those white corners are there because I set the background to white with 0.2 alpha, that's ok.

推荐答案

所以......

经过多个小时的努力事情 - 我发现了问题。
在我的情况下,问题是字体。我真的不知道为什么,但字体的作者使字体怪异(领先等),它底部有一个空白区域。我不知道为什么,但是当您编辑文本时,所有文本属性都会被忽略,但是在完成编辑后,它们会被应用。

After many hours of trying many things - I have found the problem. In my case the problem is the font. I really don't know why, but the author of the font made the font weird (leading etc.), it has a blank space on the bottom. I don't know why, but when you are editing the text all of the text properties are ignored, but after you finish editing, they are applied.

所以,如果你有类似的问题,尝试将字体更改为Arial或类似的东西。

So, if you have a similar problem, try changing the font to Arial or something similar.

有关完整说明,请参阅以下链接:链接1 链接2 。这些链接中推荐的解决方案可以避免很多麻烦,甚至可以应用于修复当您开始编辑UITextField(使用系统字体或其他特定字体)时移动到顶部的文本等问题。

For a full explanation, please consult these following links: link 1 and link 2. The solution recommended in these links can avoid you a lot of headaches and can even be applied to fix problem like text moving to the top when you start editing an UITextField (using System font or other particular fonts).

这篇关于UITextField中的文本在编辑后向上移动(编辑时居中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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