iOS - Is it possible to make UIFont SystemFont Italic and Thin (without using fontWithName:)?

1.2k views Asked by At

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 :)

2

There are 2 answers

1
Gnammo On

What about something like this:

[youLabel setFont:[UIFont fontWithName:[youLabel.font fontName] size:UIFontWeightThin]];
2
Islam.Ibrahim On

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.