I am trying to set a custom font for the label but it's not working, not sure whats the proper way to do it.
CreateLabel.brs
font = CreateObject("roSGNode", "Font")
font.uri = "pkg:/fonts/GothamMedium.ttf"
font.size = "24"
m.top.setFocus(true)
m.label1 = m.top.findNode("label1")
m.label1.font.size = 20
m.label1.text = "Hello"
' m.label1.font = font -> if uncommented, then text doesn't show up
m.label1.color="0x72D7EEFF"
end function
m.label1.font = font // is not working
CreataLabel.xml
<?xml version="1.0" encoding="utf-8"?>
<component name="CreateLabel" extends="Scene">
<interface>
<field id="label1" type="string" />
</interface>
<script type="text/brightscript" uri="pkg:/components/CreateLabel/CreateLabel.brs" />
<script type="text/brightscript" uri="pkg:/source/Main.brs" />
<children>
<Label
id="label1"
text="Narendra"
width="200"
height="100"
horizAlign="center"
vertAlign="center"
/>
</children>
</component>
You can try this-
Instead of
font.size = "24"
try
font.size = 24
ie font size should be integer. Comment below line-
'm.label1.font.size = 20
Un-comment this line-
m.label1.font = font
It should work. Color setting looks fine.
Alternatively, If you want to set the font in xml, you can try something like this-
<Label
id="label1"
text="Narendra"
width="200"
height="100"
horizAlign="center"
vertAlign="center" >
<Font role = "font" uri = "pkg:/fonts/GothamMedium.ttf" size = "24" />
</Label>
Note that every property's(field/attribute) value will be in double quotes in xml file(even integers) but this is not the case with brs files. Also make sure that font file(GothamMedium.ttf) is available at the mentioned path(pkg:/fonts/GothamMedium.ttf).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.