bold and regular look the same?
You make this statement because I think you misuse the element to pass in the incoming parameter compatibleWith
of the preferredFont
method.
You have provided a UITraitCollection
element as desired and that's why your code compile.
That's great but this trait must be a content size category to be well understood by the system ⟹ Apple doc.
You should have used the specified method this way for instance:
artistLabel.font = UIFont.preferredFont(forTextStyle: .body,
compatibleWith: UITraitCollection(preferredContentSizeCategory: .large))
How can I get a true "bold" font?
You can use the code provided by @Ritupal that is efficient or you can try the following one extracted from a WWDC 2020 video (The details of UI typography) to get a more emphasized text style:
if let artistDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .body).withSymbolicTraits(.traitBold) {
artistLabel.font = UIFont(descriptor: artistDescriptor,
size: 0.0)
}
Even if a solution has already been provided, I deemed it important to complement this answer to explain why your initial code didn't work while bringing another way to emphasize text with bold trait.