1

My app uses only system fonts, and I am creating them with function -

+ (UIFont * _Nonnull)systemFontOfSize:(CGFloat)fontSize weight:(CGFloat)weight

How Can I make System font Italic with weight UIFontWeightThin?

I cannot use the call for specific family font (fontWithName:) since I want it to be system fonts only.

Thanks :)

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
  • Possible duplicate of [UILabel font : bold and italic](http://stackoverflow.com/questions/14019441/uilabel-font-bold-and-italic) – Alex Cio Nov 02 '15 at 11:39
  • You might want to take a look at this answer http://stackoverflow.com/a/17977354/2268168 – Sudo Nov 02 '15 at 12:39
  • I don't want to use UIFont fontWithName: since I want it to be the System font (Helvetica for ios 8, SF for ios 9 etc.) – Talia Segev Nov 02 '15 at 12:39

2 Answers2

1

You should create Font Descriptor at first that contain the type of your font if it Italic or Bold or Thin, etc..

UIFontDescriptor* desc = [UIFontDescriptor fontDescriptorWithFontAttributes:
                          @{
                            UIFontDescriptorFaceAttribute: @"Thin"
                            }
                          ];

after that create a font object that hold the descriptor information

UIFont *font = [UIFont fontWithDescriptor:desc size:17];

So, set you font object to your label.

Now you got a font object using system font but you can change the the type and size of it without using fontWithName.

Islam.Ibrahim
  • 789
  • 6
  • 19
  • But how would you make a font with both "Thin" and "Italic" face attributes? You can't have duplicate keys in the dictionary. – Dielson Sales Jun 30 '16 at 12:52
  • @DielsonSales you can create two UIFontDescription objects, one for 'thin' and one for 'italic', and now you can create your font using whatever you want, even italic or thin. – Islam.Ibrahim Jun 30 '16 at 13:31
0

What about something like this:

[youLabel setFont:[UIFont fontWithName:[youLabel.font fontName] size:UIFontWeightThin]];
Gnammo
  • 255
  • 2
  • 8
  • Size is not the same thing as weight. You should not pass `UIFontWeightThin`, but should pass the size of the text to the setFont:size: method. – Kekoa May 12 '16 at 13:51