0

I'm applying small caps to lower case letters, but it appears that it also includes all digits. This is also true when I apply it only to uppercase letters.

Is there any way to exclude digits from the effect of small caps (like the label for wind speed/direction in the stock Weather app), or do I need to resort to an attributed string for that effect?

Currently I'm just applying a font to all label content:

extension UIFont {
    func smallCaps() -> UIFont {
        let settings: [[UIFontDescriptor.FeatureKey : Int]] = [
            [
                .featureIdentifier : kLowerCaseType,
                .typeIdentifier : kLowerCaseSmallCapsSelector
            ]
        ]
        let attributes: [UIFontDescriptor.AttributeName : Any] = [.featureSettings: settings]
        
        return UIFont(descriptor: self.fontDescriptor.addingAttributes(attributes), size: self.pointSize)
    }
}

I tried using kNumberCaseType and kUpperCaseNumbersSelector in the same vein as the above code, but I guessed wrong. According to the documentation it turned out not to be what I was looking for.

Andreas
  • 2,665
  • 2
  • 29
  • 38
  • "or do I need to resort to an attributed string for that effect?" Yes, although I don't know why you say "resort" as if this were some sort of bad thing. Attributed strings are _good_. In my view this is a much better alternative than just relying on the label's overall font, which requires a bunch of magic behind the scenes. All text has a font so why not say what it is, as part of the text? – matt Nov 27 '20 at 20:42
  • @matt Thank you. Yes, I see it as less desirable in this situation since then I would have to start identifying which parts of strings from third parties are letters and digits, respectively. I did not imagine the desired functionality to be much different from the existing one that already discriminates lowercase letters in order to draw small caps glyphs, which means that using several additional mechanisms to accomplish this will at best increase complexity and reduce legibility. Attributed strings therefore fall under plan B. – Andreas Nov 27 '20 at 20:58
  • 1
    I understand! But you are stuck with whatever "variants" are built-in. If there is no "variant" that does small caps for just certain characters and not others, then you will _have_ to use a font mixture. – matt Nov 27 '20 at 21:00

0 Answers0