更少的代码,更多高效!
要运行示例项目,首先克隆仓库,然后从示例目录中运行pod install
Less可以通过CocoaPods安装。要安装它,只需将以下行添加到您的Podfile中
pod "Less"
键 | 值 | 描述 |
---|---|---|
properties | 字典 | 自键值 |
tagproperties | Dictionary |
带标签子视图的键值(数组索引对应于子视图的标签,从1开始),推荐配置子视图的方式。 |
subproperties | Dictionary |
子视图的键值(数组索引对应于子视图的索引,从0开始) |
每个属性由键和值组成。键描述了所有者的键路径,值可以是什么标量常量或Rainbow表达式。
usage: [tag][key]
标签
标签 | 解析到 | 描述 | 例如。 |
---|---|---|---|
@property | 视图的键定义 | 隐藏 | |
+ | 添加键 | 视图未定义的键 | +mykey |
! | 控制事件 | 仅对UIControl有效 | !change (UIControlEventValueChanged) !click (UIControlEventTouchUpInside) |
常量(请参见LSValueParser)
标签 | 解析到 | 例如。 |
---|---|---|
# | UIColor | #FF00FF |
## | CGColor | ##FF00FF |
@ | 子脚本 | @[1,2,3]; @{title:1} |
: | 枚举 | :left = NSTextAlignmentLeft |
{{ | Rect | {{0,0},{1080,44} |
{ | Size|Point|EdgeInsets | {1080,44} | {0,2,0,2} |
{F | 字体 | {F:MicrosoftYaHei,bold,14} {F:itailc,14} {F:14} |
为了匹配屏幕尺寸,Rect、Size和Font的像素值将根据您的图稿宽度自动缩放。默认图稿宽度是1080,您可以通过[Prism setSketchWidth:]
指定它。
执行此操作后,您可以直接使用UI设计者标注的像素值。
1.1 枚举
名称 | 映射到 |
---|---|
:left | NSTextAlignmentLeft |
:right | NSTextAlignmentRight |
:center | NSTextAlignmentCenter |
:√ | UITableViewCellAccessoryCheckmark |
:i | UITableViewCellAccessoryDetailButton |
:> | UITableViewCellAccessoryDisclosureIndicator |
:value1 | UITableViewCellStyleValue1 |
:值2 | UITableViewCellStyleValue2 |
:子标题 | UITableViewCellStyleSubtitle |
1.1.1 用户自定义枚举
/* e.g.
* - plist: :your_enum1
* - output: 1
* - plist: :your_enum2
* - output: 2
*/
[LSValueParser registerEnums:@{@"{your_enum1}": @1,
@"{your_enum2{": @2}];
变量 (查看LSExpression)
usage: [unary-operator][tag][accessory][variable][logic-operator][rvalue][:][rvalueOfNot]
2.1 标签 (查看LSVariableMapper)
标签 | 映射到 | 例如。 |
---|---|---|
$ | 根视图数据 | $records |
. | 目标视图 | .frame.size |
.$ | 目标视图数据 | .$name |
@ | 活动控制器 | @title |
> | LSForm输入文本 | >出生 |
>@ | LSForm输入值 | >@birth |
2.1.1 用户自定义变量标签
用户自定义标签仅接受单个字符,如下定义D
,则可以在plist中使用$D.
。
/* e.g.
* - plist: $D.userInfo
* - mapto: [[NSUserDefaults standardDefaults] valueForKey:@"userInfo"]
*/
[LSVariableMapper registerTag:'D' withMapper:^id(id data, id target) {
return [NSUserDefaults standardDefaults];
}];
2.2 操作符
操作符 | 描述 | 例如。 |
---|---|---|
! | 逻辑非 | !$success |
- | 负数或减号 | -$height; $count-1 |
< | 小于 | $count<2 |
> | 大于 | $count>7 |
= 或 == | 等于 | $count=3; $count==3 |
!= | 不等于 | $count!=2 |
<= | 小于等于 | $count<=7 |
>= | 大于等于 | $count>=3 |
+ | 加 | $count+2 |
* | 乘 | $count*7 |
/ | 除 | $count/3 |
?: | 测试 | $value?:2; $flag?1:2 |
2.3 附加标志
附加 | 描述 | 例如。 |
---|---|---|
_ | 单向绑定(数据->视图) | $_selected |
__ | 双向绑定(数据<->视图) | $__tabIndex |
~ | 动画设置值 | ~$contentSize |
格式化器 (查看LSMutableExpression)
usage: %[tag:option]( format ),$arg1,$arg2,...
3.1 标签
标签 | 描述 | 例如。 |
---|---|---|
字符串格式 | %(goods:%@, money:%.2f),$title,$money | |
JS | JavaScript评估器 | %JS('goods:' + $1 + ', money:' + $2),$title,$money |
AT | attributed string | 当前不可用 |
3.1.1 用户自定义格式标签 (查看LSVariableEvaluator)
/* e.g. Format string to array
* - plist: %S2A(/),$str
* - input: str="a/b/c"
* - output: @[@"a",@"b",@"c"]
*/
[LSVariableEvaluator registerTag:@"S2A" withFormatterer:^id(NSString *format, id value) {
return [value componentsSeparatedByString:format];
}];
3.1.2 JavaScript评估器 (查看LSVariableEvaluator)
Prism使用JavaScriptCore来评估JavaScript。
要使用JavaScript评估器,只需在plist中声明%JS(脚本),vars
。Prism将变量作为$1
、$2
... $N
传递给脚本。
此外,您可以通过类似于%JS:type
的选项来定义返回值的类型,这里的类型默认为string
,也可以是bool
、int32
、date
、rect
等。它们对应于[JSValue toXx]
。
3.1.3 字符串格式化器 (查看LSString, LSStringFormatter)
标志 | 描述 | 例如。 |
---|---|---|
# | 数字格式,接受NSNumber参数 | %(%#.2f),$number |
J | Json,接受NSDictionary, NSArray参数 | %(%J),$dict |
<t> | 日期格式,接受NSDate, NSNumber参数 | %(%<t:yyyy-MM-dd>),$date |
<T> | 日期模板,接受NSDate, NSNumber参数 | %(%<T:MMMy>),$date |
<UE> | URL编码,接受NSString参数 | %(%<UE>),$param |
<UEJ> | 编码Json,接受NSDictionary, NSArray参数 | %(%<UEJ>),$dict |
3.1.4 用户自定义格式标志 (查看LSStringFormatter)
/* e.g. Format array to string
* - plist: %(%<A2S:/>),$arr
* - input: arr=@[@"a",@"b",@"c"]
* - output: "a/b/c"
*/
[LSStringFormatter registerTag:@"A2S" withFormatterer:^NSString *(NSString *format, id value) {
return [value componentsJoinedByString:format];
}];
galenlin, [email protected]
Less可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。