iOS: How can i set a non system font family, style, size of UILabel?
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]
- Download the font.
- Drag and drop the different font family in your project.
- Add the font family in .plist file (Fonts provided by application).
- Check whether your font family is added in your "Build Phases" or not.
- Now select a "New file" in your project and add a ".h" file in the project.
- In the ".h" file enter "#define any_name@"font_name"
- Now define it in the label setFont......
You're all done but remember don't add the ".ttf" with your "font_name".
Thanks!
精彩评论