代码之家  ›  专栏  ›  技术社区  ›  Paul Chernoch

在AS3列表控件(flash.controls.List)中设置字体名称和大小

  •  3
  • Paul Chernoch  · 技术社区  · 15 年前

            var myFormat:TextFormat = new TextFormat();
            myFormat.font = config.settings["list font name"];
            myFormat.size = Number(config.settings["list font size"]);
            list.setStyle("textFormat", myFormat);
    

    没有骰子。

    3 回复  |  直到 15 年前
        1
  •  3
  •   George Profenza    14 年前

    可以按实例、类和全局设置样式。

    setRendererStyle 而不是 设置样式 ,因为您正在为每个单元格呈现器/项设置样式,而不是为列表本身设置样式(如果这有意义的话):

    list.setRendererStyle('textFormat',myFormat);
    

    也可以使用全局样式 StyleManager

    请确保字体已嵌入,然后尝试

    import fl.managers.StyleManager;
    
    var myFormat:TextFormat = new TextFormat(config.settings["list font name"],config.settings["list font size"]);
    StyleManager.setStyle('embedFonts',true);
    StyleManager.setStyle('textFormat',myFormat);
    
        2
  •  1
  •   Will Mavis    15 年前
        3
  •  1
  •   Koby.G    7 年前

    上面的答案似乎已经很老了,而且对我已经不起作用了。。。

    无论如何,我找到了一种适合我的方法(在Flash CS6上): (如上所述,不要忘记嵌入字体)

    import fl.managers.StyleManager;
    import flash.text.TextFormat
    
    var myFormat:TextFormat = new TextFormat();
    myFormat.font = "Arial";  // your font
    myFormat.size = 20;  // your font size
    myList.setRendererStyle('textFormat',myFormat);
    myList.rowHeight = 30;  // if you want to change the row height (to better match the text size)