如何更改 "i" 圆圈颜色(标题颜色)

How to change the "i" circle color (tittle color)

是否要更改 swift 中 "i" 字符的标题颜色?

我想将 "i" 的圆圈的颜色更改为橙​​色,但我不知道该怎么做。

例如,我有这个:

我想这样做:

我想用 NSAttributedString 做到这一点,但我找不到任何东西。

"tittle" 是 "i" 字符的圆圈,当我在网上搜索如何更改那个颜色时,我得到的结果只是更改 UINavigationBar 标题

通过使用一些 Unicode 技巧,您可以(某种程度上)做到这一点。诀窍是 combining dot above 字符 (U+0307)。将其设为不同的颜色并调整其基线以完全重叠 i:

上的点
let attributes = [
    NSFontAttributeName: UIFont.systemFontOfSize(50, weight: UIFontWeightHeavy)
]
let dotAttributes = [
    NSFontAttributeName: UIFont.systemFontOfSize(60, weight: UIFontWeightHeavy),
    NSForegroundColorAttributeName: UIColor.redColor(),
    NSBaselineOffsetAttributeName: -15
]

let attributedString = NSMutableAttributedString(string: "cli\u{307}ck", attributes: attributes)
attributedString.setAttributes(dotAttributes, range: NSMakeRange(3, 1))

textLabel.attributedText = attributedString

结果:

缺点是您必须试验 dotAttributes 中的字体大小和基线偏移量才能使其与您的常规文本配合得很好 - 它们没有通用规则。