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
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
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.
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
#import <UIKit/UIKit.h>
@interface InsetTextField : UITextField
@property (assign, nonatomic) UIEdgeInsets insets;
@end
#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. :-/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With