开发者

iOS: How can i set a non system font family, style, size of UILabel?

开发者 https://www.devze.com 2023-03-21 15:04 出处:网络
I am trying to use a font which is not a system font in the bottom way [pickerLabelLeft setFont:[UIFont fontWithName:@\"DaxOT-Bold\" size:20]];

I am trying to use a font which is not a system font in the bottom way

[pickerLabelLeft setFont:[UIFont fontWithName:@"DaxOT-Bold" size:20]];
[pickerLabelLeft setFont:[UIFont fontWithName:@"Dax OT-Bold" size:20]];
[pickerLabelLeft setFont:[UIFont fontWithName:@"Dax-OT-Bold" si开发者_运维百科ze:20]];

But none of these is working.

But if i use like below then it can altleast get the system font with size

[pickerLabelLeft setFont:[UIFont boldSystemFontOfSize:20]];

Can anyone help me?


Check out this short tutorial on how to use custom fonts.

It's important to understand that the file name of the font (e.g. DaxOTBold.ttf) and the actual name of the font are 2 different things. Most of the time they are the same but there are some fonts that have a name that is slightly different from the file name. For example "Arial Rounded Bold.ttf" has the actual name "Arial Rounded MT Bold". Make sure that you are using the correct name.

In this example in the plist you would use "Arial Rounded Bold.ttf" and in your code you'd use [UIFont fontwithName:@"Arial Rounded MT Bold" size:20]


  1. Download the font.
  2. Drag and drop the different font family in your project.
  3. Add the font family in .plist file (Fonts provided by application).
  4. Check whether your font family is added in your "Build Phases" or not.
  5. Now select a "New file" in your project and add a ".h" file in the project.
  6. In the ".h" file enter "#define any_name@"font_name"
  7. Now define it in the label setFont......

You're all done but remember don't add the ".ttf" with your "font_name".

Thanks!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号