Talia Segev
Talia Segev

Reputation: 11

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

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

Upvotes: 1

Views: 1267

Answers (2)

Islam.Ibrahim
Islam.Ibrahim

Reputation: 889

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.

Upvotes: 1

Gnammo
Gnammo

Reputation: 255

What about something like this:

[youLabel setFont:[UIFont fontWithName:[youLabel.font fontName] size:UIFontWeightThin]];

Upvotes: 0

Related Questions