开发者

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 开发者_C百科then it cuts the text again. like this

Why Text is cutting from bottom in UITextField?

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:

Why Text is cutting from bottom in UITextField?

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

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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜