嗨,我在iOS中使用嵌入字体时遇到问题。
UILabel无法正常显示。
它应垂直和水平居中。
感谢。
答案 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
属性 - 这解决了我的应用中自定义字体的类似问题。