Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Text is cutting from bottom in UITextField?

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 enter image description here

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

like image 323
Mashhadi Avatar asked Sep 07 '11 12:09

Mashhadi


3 Answers

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

like image 142
JeanLuc Avatar answered Oct 11 '22 17:10

JeanLuc


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:

Image

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.

like image 20
dvs Avatar answered Oct 11 '22 18:10

dvs


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. :-/

like image 26
colinta Avatar answered Oct 11 '22 18:10

colinta