gpt4 book ai didi

objective-c - 属性字符串中的上标美分

转载 作者:搜寻专家 更新时间:2023-10-30 19:59:40 25 4
gpt4 key购买 nike

我试图让我的标签看起来像这样:

enter image description here

但是使用属性字符串,我设法得到了这个结果:

enter image description here

我的代码:

NSString *string = [NSString stringWithFormat:@"%0.2f",ask];

NSMutableAttributedString *buyString = [[NSMutableAttributedString alloc] initWithString:string];

[buyString addAttribute:NSFontAttributeName
value:[UIFont systemFontOfSize:15.0]
range:NSMakeRange(2, buyString.length - 2)];

self.labelBuy.attributedText = buyString;

如您所见,点后的数字位于下方,我想将它们弹出到顶部作为第一个示例。有什么方法可以设置属性字符串框架吗?

最佳答案

你必须使用 NSBaselineOffsetAttributedName

来自文档:

NSBaselineOffsetAttributeName
The value of this attribute is an NSNumber object containing a floating point value indicating the character’s offset from the baseline, in points. The default value is 0.
Available in iOS 7.0 and later.

从你的例子:

[buyString addAttribute:NSBaselineOffsetAttributeName
value:@(10.0)
range:NSMakeRange(2, buyString.length - 2)];

您可能必须更改该值以满足您的需要。

关于objective-c - 属性字符串中的上标美分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25367017/

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