Sketch基本结构
MSTextLayer文字控件
MSShapePathLayer图形基控件
SKetch只有文字和图形的概念
像iOS上面的UIImageView,UIButton,TextField都是用基于MSShapePathLayer的子控件来表示的
MSSymbolInstance就是Symbol控件(重复使用控件)
OC属性
你需要的很多属性都是官方文档上面没有标示出来的,只能通过头文件和一些写好的第三插件的JS代码名称来猜测,在动态调试看是否是需要的属性.
具体可以看我写的sketch插件项目来了解
SObject类是将Layer的所有属性全部转换成对应的属性,后续代码逻辑就和Sketch没有关系, 这个项目的目的就是将Sketch对应控件的属性提取出来转换Swift代码
JS属性
content: Application就是整个应用
selection: Represents the layers that the user has selected.
layer: 基本对象等于UIView
style: layer对象的样式
fills: style的集合
files有fillType,color方法
Text一般为UILabel
Group一般为UIButton
Group为Button时,可以遍历其item然后拿到text
//Style
fill.fillType() == 0 //表示的是颜色??
fillType表明的是border,背景颜色或者什么的
// groupLayer
Button.iterate(function(item) {
if (item.isText) { // 拿到Button的TextLayer,然后可以拿到字体样式,大小,颜色
}
}
// ShapeLayer
// 背景颜色 fills是array,每个代表一个style
item.sketchObject.style().fills()[0].color()
layer.style().fills().firstObject().color()
//Sketch代码片段
// 获取选择的layers
var selection = context.api().selectedDocument.selectedLayers
// 遍历layers
selection.iterate(function(item) {
});
// 判断layer类型
item.isText, item.isShape, item.isImage, item.isGroup
item.isPage, item.isArtboard
// 首字母小写
string.charAt(0).toLowerCase() + string.slice(1);
// 移除空格
str.replace(/\s+/g, '');
// 获取Text的text属性
item.text
// 获取字体名称
item.sketchObject.fontPostscriptName()
// 获取字体大小
item.sketchObject.fontSize()
// 字体颜色
item.sketchObject.textColor()
// 字体对齐格式
item.alignment
// 背景颜色
item.sketchObject.backgroundColor()
// frame
item.frame