gpt4 book ai didi

ios - 如何调整 UiLabel 的基线偏移?

转载 作者:搜寻专家 更新时间:2023-10-31 22:49:53 25 4
gpt4 key购买 nike

我的应用使用自定义字体来显示整个应用的信息。

但他们的基线存在一些问题,如下图所示:

enter image description here

我需要修复“X 4”使其在垂直的红色框中居中。

我该如何解决这个问题?

最佳答案

像在 Swift 中一样使用调整后的基线偏移设置属性字符串:

let sttrStr = NSAttributedString.init(string: "your text",
attributes:[NSAttributedStringKey.baselineOffset: -10])
textLabel.attributedText = attrStr

或者像在 ObjC 中那样:

NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:@"your string"
attributes:@{ NSBaselineOffsetAttributeName : @-10 }];
textLabel.attributedText = attrStr;

根据 SO 回答 here

关于ios - 如何调整 UiLabel 的基线偏移?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31072006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com