Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我可以为系统UIFont设置上升或下降吗?_Ios_Objective C_Uilabel_Uifont - Fatal编程技术网

Ios 我可以为系统UIFont设置上升或下降吗?

Ios 我可以为系统UIFont设置上升或下降吗?,ios,objective-c,uilabel,uifont,Ios,Objective C,Uilabel,Uifont,我正在使用以下代码使用UILabel创建警报徽章: [label setText:@"67"]; UIFont * font = [UIFont systemFontOfSize:11]; [label setFont:font]; [label sizeToFit]; [label setTextAlignment:NSTextAlignmentCenter]; [label setBackgroundColor:[UIColor yellow

我正在使用以下代码使用UILabel创建警报徽章:

    [label setText:@"67"];
    UIFont * font = [UIFont systemFontOfSize:11];
    [label setFont:font];
    [label sizeToFit];

    [label setTextAlignment:NSTextAlignmentCenter];
    [label setBackgroundColor:[UIColor yellowColor]];
    [label setTextColor:[UIColor whiteColor]];
    label.layer.cornerRadius = label.frame.size.height/2;

一切正常,但文本的垂直对齐不正确。它更接近顶部边缘。如何在UILabel的垂直中心对齐文本


我了解了UIFont的升序和降序属性,我可以使用它们来对齐UILabel垂直中心的文本。

要垂直对齐UILabel的文本,请使用-

myLabel.numberOfLines = 0;
[myLabel sizeToFit];

对于详细的答案检查

您可以对标签文本使用属性字符串而不是普通的
NSString
(因此使用
attributedText
属性而不是
text
),并使用
NSBaselineOffsetAttributeName
属性。

另一种解决方案是将
UILabel
子类化,以便为标签添加边距,因此您可以定义自定义的“上边距”以补偿基线偏移


请参阅以查看实施详细信息。

它有更多控件。很高兴知道这一点。