Why Text is cutting from bottom in UITextField?

廉价感情. 提交于 2020-01-12 18:27:07

问题


I am using a custom font in my text fields and labels in my whole application. My font name is "digital-7.ttf". now the problem is that text in my labels is good but in the UITextFields it is cutting text from bottom. when textfield is editing then text is good but when editing is done then it cuts the text again. like this

in this way i am setting its font style [txtFld setFont:[UIFont fontWithName:@"digital-7" size:25.0]];

and font has been added in info.plist

Please help me


回答1:


i just had a similar problem with a custom font in UITextField, but in my case it cut off my umlauts on the top.

i opened the font with FontForge and adjusted the HHead Ascent Offset in Element -> OS/2 -> Metrics to the same value as Win Ascent Offset

in your case it is probably the HHHead Descent Offset. try modifiying this value




回答2:


I faced the same problem with the same Digital-7 font (albeit italic). To build on JeanLuc's answer, the only sane way to do this is to modify the metrics in a font editor. I also used FontForge, but the steps I took were somewhat different. I opened the font, went to Element > Font Info... > OS/2 > Metrics and changed the HHead Descent value (represents line spacing on the Mac) to the negative of the Win Descent value (line spacing on Windows). See below:

Also make sure the Win Ascent and HHead Ascent values are the same. You may also want to change the name of the modified font. Once you've made your changes, click OK, then File, Generate Fonts..., choose ttf format and save.




回答3:


Editing a font file seems a bit heavy handed.

Did you try Malcolm's suggestion? I am using a custom font, and a custom subclass that accepts a UIEdgeInset

InsetTextField.h

#import <UIKit/UIKit.h>

@interface InsetTextField : UITextField

@property (assign, nonatomic) UIEdgeInsets insets;

@end

InsetTextField.m

#import "InsetTextField.h"

@implementation InsetTextField

- (CGRect) textRectForBounds:(CGRect)bounds
{
    return UIEdgeInsetsInsetRect([super textRectForBounds:bounds], self.insets);
}

- (CGRect)editingRectForBounds:(CGRect)bounds
{
    return UIEdgeInsetsInsetRect([super editingRectForBounds:bounds], self.insets);
}

@end

If Digital-7 is still misbehaving, I think you'll have no other recourse than to change the font file. :-/




回答4:


You should increase textfield frame height so its solve your problem,or decrease the font size of text




回答5:


this problem is in Xcode 3.2.5. In earlier versions same code works good. :)



来源:https://stackoverflow.com/questions/7333582/why-text-is-cutting-from-bottom-in-uitextfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!