嵌入式字体在iOS中未正确定位

时间:2013-02-11 05:26:05

标签: ios

嗨,我在iOS中使用嵌入字体时遇到问题。

UILabel无法正常显示。

它应垂直和水平居中。

感谢。

2 个答案:

答案 0 :(得分:0)

对于VerticalAlignment。

YourLabel.textAlignment = UIControlContentVerticalAlignmentCenter;

垂直和水平居中。

theYourLabel.textAlignment = UIControlContentVerticalAlignmentCenter;
theYourLabel.textAlignment = UITextAlignmentCenter;

另一种方式是:

YourYourLabelName.center = parentViewField.center;

YourLabel = [[UIYourLabel alloc] initWithFrame:CGRectMake("As You Want")];
YourLabel.center = CGPointMake(CGRectGetWidth(someView.bounds)/2.0f, CGRectGetHeight(someView.bounds)/2.0f);

替代方法您可以使用UITextField的子类UIControl,它继承了UIControl的contentVerticalAlignment属性。

textField.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;

您可以使用此属性将文本对齐在顶部。 您可以使用属性userInteractionEnabled属性禁止用户编辑文本。

答案 1 :(得分:0)

在某些情况下,iOS控件(如UILabels,UIButtons等)无法正确定位自定义字体,而无需修补字体文件本身。有关详细信息,请参阅以下问题:

Custom installed font not displayed correctly in UILabel

其中一个答案建议使用Apple提供的ftxdumperfuser工具来更改字体文件的ascender属性 - 这解决了我的应用中自定义字体的类似问题。