alternate six and nine on the Apple Watch

Hi, I struggle to use the alterante six and nine of the San Francisco Compact Font in my Watch App. Can anybody tell me how to use them in Swift?


I use this code in my iOS-App but it fails on the WatchKit:

func alternateNumberfont() {
        let bodyFontDescriptor = UIFontDescriptor.preferredFontDescriptorWithTextStyle(UIFontTextStyleBody)
        let bodyAltStyle1Descriptor = bodyFontDescriptor.fontDescriptorByAddingAttributes(
            [
                UIFontDescriptorFeatureSettingsAttribute: [
                    [
                        UIFontFeatureTypeIdentifierKey: kStylisticAlternativesType,
                        UIFontFeatureSelectorIdentifierKey: kStylisticAltOneOnSelector
                    ]
                ]
            ])
        let altStyle1BodyFont = UIFont(descriptor: bodyAltStyle1Descriptor, size: 12.0)
        maxDrawDist.font = altStyle1BodyFont
    }

Except for prototyping UIs for testings, devs are prohibited from using SFFont (system only) in their own apps,

Try this in the playground.

import UIKit
let size: CGFloat = 30
let weight = UIFontWeightRegular
var features: [[String: AnyObject]] = [[
UIFontFeatureTypeIdentifierKey: kStylisticAlternativesType,
UIFontFeatureSelectorIdentifierKey: kStylisticAltOneOnSelector
]]
let fontDescriptor = UIFont.systemFontOfSize(size, weight: weight).fontDescriptor().fontDescriptorByAddingAttributes(
    [UIFontDescriptorFeatureSettingsAttribute: features]
)
let alternate69Font = UIFont(descriptor: fontDescriptor, size: size)
let regularLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 100))
regularLabel.font = UIFont.systemFontOfSize(size)
regularLabel.text = "69"
let altLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 100))
altLabel.font = alternate69Font
altLabel.text = "69"

Yeah, this works (in the playground). Will try it in my actual App next time possible and give you feedback. Thanks so long.

Sadly it won't work in the Interface.Controller.swift of my WatchApp. If I implement this in my WatchApp the compiler/debugger ports this issues:

On line 5 it says: Use of unresolved identifier 'kStylisticAlternativesType'

On line 6 it says: Use of unresolved identifier 'kStylisticAltOneOnSelector'

And on line 16 it says: Value of type 'WKInterfaceLabel' has no member 'font'

I tried this code and it appears that the WatchKit label WKInterfaceLabel doesn't have a font property.

Use the attributedString property instead.

See below for a cleaned up version of the code and updated for Swift 5 and iOS 13.

Also, I created a library to easily use these Stylistic Alternative features of San Francisco font:

https://github.com/djfitz/SFFontFeatures

Doug Hill

Code Block
let features =
[
[ UIFontDescriptor.FeatureKey.featureIdentifier: kStylisticAlternativesType,
UIFontDescriptor.FeatureKey.typeIdentifier: kStylisticAltOneOnSelector ]
]
let fontDescriptor = UIFont.systemFont(ofSize: 14, weight: .regular)
.fontDescriptor
.addingAttributes( [UIFontDescriptor.AttributeName.featureSettings: features] )
let alternate69Font = UIFont(descriptor: fontDescriptor, size: 14)
let theString = NSMutableAttributedString.init( string: "69",
attributes:[NSAttributedString.Key.font : alternate69Font] )
watchLabel.setAttributedText(theString)



alternate six and nine on the Apple Watch
 
 
Q