【问题标题】:Sketch API - Text stylingSketch API - 文本样式
【发布时间】:2023-04-02 09:53:01
【问题描述】:

我对 Sketch API/Sketch API 文档有很多问题。 在文本上添加一些样式(字体大小、字体系列等)的正确方法是什么?

这是我在循环中的文本。

 var text = group.newText(
        {
            text: Colors.groupNames[index],
            frame: new api.Rectangle(50, 0, 50, 50),
        }
    );

【问题讨论】:

    标签: api text sketch-3


    【解决方案1】:

    你应该可以做到:

    var text = group.newText({font: NSFont.fontWithName_size("OpenSans-Bold", 15), text:"Hello World"})
    

    但是API中有一个bug,解决方法是:

    var text = group.newText({text: "Hello World"})
    text._object.setFont(NSFont.fontWithName_size("OpenSans-Bold", 15))
    

    字体名称是没有扩展名的字体文件名。您可以在 ~/Library/Fonts 中找到它们。

    您可以在文本层上设置的其他属性在here 中列出,下面是docs 中的示例:

    var text = group.newText({fixedWidth: true, alignment: NSTextAlignmentCenter, systemFontSize: 24, text:"Hello World"})
    text.frame = new sketch.Rectangle(0, 160, 200, 30) // adjust the frame last, after the font/size/alignment etc has been set up
    

    【讨论】:

      猜你喜欢
      • 2019-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多