MCM*_*tan 3 objective-c nsattributedstring
我试图让我的标签看起来像这样:

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

我的代码:
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;
Run Code Online (Sandbox Code Playgroud)
如你所见,点后的数字,保持在下面,我想将它们作为第一个例子弹出到顶部.有没有办法设置属性字符串框架?
你必须使用NSBaselineOffsetAttributedName.
来自doc:
NSBaselineOffsetAttributeName
此属性的值是一个NSNumber对象,其中包含一个浮点值,指示字符与基线的偏移量(以磅为单位).默认值为0.适用
于iOS 7.0及更高版本.
从你的例子:
[buyString addAttribute:NSBaselineOffsetAttributeName
value:@(10.0)
range:NSMakeRange(2, buyString.length - 2)];
Run Code Online (Sandbox Code Playgroud)
您可能需要更改值以满足您的需求.
| 归档时间: |
|
| 查看次数: |
2304 次 |
| 最近记录: |