How to make an italic UILabel without caring about the size?

Viewed 5768

I have a UILabel, whose text or attributedText properties I update programatically. Under some cases, I'd like to italicize it. I could either:

A) set the UILabel.font property:

myLabel.font = [UIFont italicSystemFontOfSize: 12.0];

B) or use an attributed string to do something similar:

myLabel.attributedText = [[NSAttributedString alloc] initWithString: @"my text" attributes: @{NSFontAttributeName: [UIFont italicSystemFontOfSize: 12.0]}]]

But I don't want to care about the size. I just want the "default" font AND size, but in italic. Currently, I'm actually using the obliqueness attribute:

NSMutableAttributedString *text = [[NSMutableAttributedString alloc]
    initWithString: @"My Text"
    attributes: @{NSObliquenessAttributeName: @(0.5)}];
myLabel.attributedText = text;

This makes it so I don't have to care about whatever the size is, but I think obliqueness just approximates italics.

2 Answers
Related