Description
I am trying to use costum fonts.
I got the idea from this blog post and it was working fine
https://medium.com/@dabit3/adding-custom-fonts-to-react-native-b266b41bff7f#.13fe3uz08
But now I added the font called Lantinghei.ttc
(that is available on El Captain by default) to my application, listed it on Info.plist as well.
When I print all the font available to my application to the console using the code mentioned in the above blog:
for (NSString* family in [UIFont familyNames])
{
NSLog(@”%@”, family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(@” %@”, name);
}
}
it gives me output as
Lantinghei TC
FZLTTHB--B51-0
FZLTZHB--B51-0
FZLTXHB--B51-0
Lantinghei SC
FZLTZHK--GBK1-0
FZLTTHK--GBK1-0
FZLTXHK--GBK1-0
Using fontFamily: Lantinghei TC
gives me Lantinghei TC Heavy
and using fontFamily: Lantinghei SC
gives me Lantinghei SC Heavy
.
There is no way for me to set the ExtraLight
and DemiBold
option of the font. When I open the font in FontBook, it shows me all three options of Heavy
, DemiBold
and ExtraLight
If I use the other 3 weird name listed above, it gives me the same effect no matter which of the 3 I use.
I created a swift project and used those 3 wired name, and it seems to render fine. But in RN, it has no effect than to render the Heavy
font.
Here the minimal code I used to reproduce the issue:
'use strict';
import React, {
AppRegistry,
Component,
StyleSheet,
Text,
View
} from 'react-native';
class FontTest extends Component {
render() {
return (
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
);
}
}
const styles = StyleSheet.create({
welcome: {
fontFamily: 'FZLTXHK--GBK1-0',
fontSize: 20,
textAlign: 'center',
margin: 40,
},
});
AppRegistry.registerComponent('FontTest', () => FontTest);
- react-native version: 0.20 (but the problem persisted in earlier versions too)
- I tested it on IOS, i did not know how to print the name of custom fonts that I can use on android
- OS: Mac OSX El Capitan 10.11.2
Activity
Kureev commentedon Feb 20, 2016
Have you tried to use a fontWeight?
aakashsigdel commentedon Feb 20, 2016
@Kureev Yes I have, with the same result.
Kureev commentedon Feb 20, 2016
Well, in this case I don't know what to advice. Maybe you can try to convert
.ttc
to.ttf
and try again, but it's just a guessgrabbou commentedon Feb 26, 2016
I've been always explicit with the font names, that is, I was setting the font name to be
Lato Bold
instead of justLato
& fontWeight. That's been working well.cesardeazevedo commentedon Mar 2, 2016
@grabbou You just nailed it, i've been struggling with a specifically font in these last days, in my case was
Axis
font, and it didn't work to just rename the font file, what i did was open the font on FontForge and rename from there toAxis-Font
and export to.ttf
, i still don't know why, but it worked, thanks.aakashsigdel commentedon Mar 2, 2016
@Kureev I opened the font in a font converting app. I think the issue was with some kind of font post script.
The post script had those weird names
FZLTTHB--B51-0
FZLTZHB--B51-0
FZLTXHB--B51-0
The app changed those name to the sane font names. And everything worked fine.
rainer-liao commentedon Apr 27, 2016
Can't use custom font in React Native iOS.
My font family name is "Impact".
In
RCTConvert.m
I find when I use font family "Impact", the code
return
false
sobestMatch
returnnil
.I also find other custom font families work fine. Just "Impact" don't.