iPe*_*ter 2 ios nsmutableattributedstring swift
这就是我想要实现的目标。
我使用了一个,获取字符$attributedString的范围并对其应用属性,如下所示:
let str = "$4"
let r1 = str.range(of: "$")!
let n1 = NSRange(r1, in: str)
let atrStr = NSMutableAttributedString(string: str)
atrStr.addAttributes([NSAttributedStringKey.font : UIFont.systemFont(ofSize: 25)], range: n1)
atrStr.addAttributes([NSAttributedStringKey.foregroundColor : UIColor.lightGray], range: n1)
lbl.attributedText = atrStr
Run Code Online (Sandbox Code Playgroud)
但结果是
如何从下到上更改该特定字符的对齐方式?
你需要baselineOffset使用NSMutableAttributedString
计算两种字体大小之间的差异
let offset = baseFont.capHeight - smallFont.capHeight
Run Code Online (Sandbox Code Playgroud)
添加名为baselineOffset的新属性
atrStr.addAttributes([NSAttributedString.Key.baselineOffset:offset], range: n1)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3554 次 |
| 最近记录: |