[英]Roku: BrightScript: How to set custom font and color for Label?
我正在尝试为 label 设置自定义字体,但它不起作用,不确定正确的方法是什么。
创建标签.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 = 字体 // 不工作
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>
你可以试试这个-
代替
font.size = "24"
尝试
font.size = 24
即字体大小应为 integer。 在下面的行评论 -
'm.label1.font.size = 20
取消注释此行 -
m.label1.font = font
它应该工作。 颜色设置看起来不错。
或者,如果你想在 xml 中设置字体,你可以试试这样的 -
<Label
id="label1"
text="Narendra"
width="200"
height="100"
horizAlign="center"
vertAlign="center" >
<Font role = "font" uri = "pkg:/fonts/GothamMedium.ttf" size = "24" />
</Label>
请注意,在 xml 文件(甚至整数)中,每个属性的(字段/属性)值都将用双引号括起来,但 brs 文件并非如此。 还要确保字体文件 (GothamMedium.ttf) 在上述路径 (pkg:/fonts/GothamMedium.ttf) 中可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.