1

I have created a custom renderer as i wanted to use "SF Pro Display" font and using UIFont.SystemFontOfSize(size , weight) i get output as .SFUI-weight .Below is the code i used for custom font -

var descriptor = new UIFontDescriptor().CreateWithFamily("SF Pro Display");
            if ((attributes & FontAttributes.Bold) != 0)
        {
            var traits = (UIFontDescriptorSymbolicTraits) 0;
            traits = traits | UIFontDescriptorSymbolicTraits.Bold;

            descriptor = descriptor.CreateWithTraits(traits);
            Control.Font = UIFont.FromDescriptor(descriptor, (nfloat) label.FontSize);
            
        }

Here the problem is FontAttributes and UIFontDescriptorSymbolicTraits only provide options as Bold,Italic and i wanted Semibold ,Medium ,regular also .I have gone through some similar question but solution are in Swift and those in-build methods are not in C#.By above code i get output SFProDisplay-Bold similarly i want for SFProDisplay-Medium etc.

Went through this below links, How can I get weight of a UILabel? iOS - How to detect whether a font is bold/black/heavy...?

0

1 Answer 1

0

Actually, I cannnot find addingAttributes method for FontDescriptor. So you may try the following code as an alternative:

var systemFont = UIFont.SystemFontOfSize(24, UIFontWeight.Semibold);
var descriptor = systemFont.FontDescriptor.CreateWithFamily("SF Pro Display");
Control.Font = UIFont.FromDescriptor(descriptor, 24);

Hope it works for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.