UIFontWeightTrait Ignored When Creating a New Font – TextKit Bug or a Jared Goof?
Given the following code and a device running iOS 7.1 or later:
NSDictionary *fontTraitsDictionary = @{UIFontWeightTrait : @(-1.0)};
NSDictionary *attributesDictionary = @{
UIFontDescriptorFamilyAttribute : @"Helvetica Neue",
UIFontDescriptorTraitsAttribute : fontTraitsDictionary
};
UIFontDescriptor *ultraLightDescriptor = [UIFontDescriptor fontDescriptorWithFontAttributes:attributesDictionary];
UIFont *shouldBeAnUltraLightFont = [UIFont fontWithDescriptor:ultraLightDescriptor size:24];
NSLog(@"%@", shouldBeAnUltraLightFont);
I would expect the value of shouldBeAnUltraLightFont
to be an instance of HelveticaNeue-UltraLight, but instead it is:
<UICTFont: 0x908d160> font-family: "Helvetica"; font-weight: normal; font-style: normal; font-size: 24.00pt
I am following the Apple documentation as far as I understand it. Why is the font family and font weight information completely ignored?
Things I’ve Tried
Here are some of the things I’ve tried:
- I’ve tried other family names like Helvetica, Avenir, etc.
- I’ve tried other font weights in the valid range from -1 to 1, in increments of 0.25
Regardless of these changes, the font returned is always a vanilla instance of Helvetica at normal weight. The only exception is when I remove the UIFontDescriptorTraitsAttribute
key/value pair from the attributes dictionary. This results in a 24-point, normal-weight instance of whatever font family I specified.
Things I Can’t Use
- I can’t use any of the preferred fonts because they’re not guaranteed to be an ultra-light weight.
- I can’t use any of the symbolic font traits because none of them specify an ultra light or even a light weight font.
- I can’t hard-code the font name for Helvetica Neue UltraLight for reasons described below.
Why This Matters
A design calls for an ultra-light system font, which in practice should be an instance of Helvetica Neue UltraLight. I could manually specify something like this:
font = [UIFont fontWithName:@"HelveticaNeue-UltraLight"];
The problem with this approach is that it’s prone to errors. When iOS 7.0.3 was released, Apple quietly renamed all the Helvetica Neue italic font filenames, which broke a lot of apps that were manually specifying the old font names. So I need a solution that is resistant to future errors of this kind, but still allows me to get a specific weight of a system font.
I’ve cross-posted this to Stack Overflow if you have an answer.
Why are Inflation and Deficits Bad?
My old college friend, writer and philosopher Adam Kotsko, on the misleading common rhetoric about defecits and inflation:
A disproportionate amount of political debate centers around vague abstractions: government spending, deficits, and inflation. The latter two are supposed to be particularly horrible, leading to hyperinflation (and therefore Hitler) or else mountains of debt that are impossible to pay off (and therefore Hitler).
A moment’s reflection will reveal that these three technocratic abstractions are actually code words for “stuff that makes rich assholes powerful.”
Birthday Cake M&M's – The Dawn of a New Era
I tried Birthday Cake M&M’s for the first time tonight, and they are far stranger than I had expected. I had assumed that, like their Peanut Butter or – crucially – their Pretzel forbears, each candy piece would contain a morsel of actual cake. The truth is that Birthday Cake M&M’s are concocted to taste like fake processed chocolate cake – an artificial artificial flavor.
I’m tempted to cite the Jelly Belly’s Dr. Pepper jelly bean as a precursor, but that’s merely intended to amaze the customer with a feat of flavor science. In contrast, Birthday Cake M&M’s take food engineering as a given, presenting the (synthetic) synthetic cake flavor as an end in itself. Birthday Cake M&M’s assume that the customer already craves artificial chocolate cake for its own sake, not because it tastes like a slice of Real™ chocolate cake (which it doesn’t).
In the ontology of Birthday Cake M&M’s, it isn’t:
artificial chocolate cake flavor
but instead:
artificial chocolate cake flavor
It’s essential to point out that artificial chocolate cake flavor cannot exist independently of Birthday Cake M&M’s. On the contrary, it is Birthday Cake M&M’s that bring artificial chocolate cake flavor into being, as a pond ripple is born from a stone.
Birthday Cake M&M’s shift the boundary between the real and the artificial forward by many millenia. It’s as if everything that came before artificial chocolate cake has now been blessed. Agricultural advancements, technological innovation, manufactured goods, indeed the whole of human ingenuity, have been adopted into the family of the real – at least up through the point in human history that cake mix started shipping in a box.
Thus, through the second-order synthesis of the Birthday Cake M&M, the first-order synthetic is no longer distinct from what is genuine. The synthetic is synonymous with the real. Technology is nature, and vice versa. The Buddha is at home in a Xanax bottle.
A new era has dawned.
Your New National Health Service
“The Best of Both Worlds” – Yours Truly on CMD+Space
I was a guest on today’s episode of Mike Hurley’s CMD+Space podcast. Check it out if you’re curious about my thoughts on the past and future of App.net, the strategy behind the design of Unread, and my feelings on the decline of the indie iOS software business.