Skip to content

使用样式class

zhenglibao edited this page Oct 26, 2020 · 3 revisions

从2.8.0版本开始,每个视图元素均支持class标签,如下:

<UIView name="containerView" class="button" layout="flex:1,paddingHorizontal:20" attr="">

其中button是在全局样式表中定义的文件,格式如下: system.style

<?xml version="1.0" encoding="utf-8"?>

<styles>
    <style name="button">
        <attr name="bgColor">#333333</attr>
        <attr name="cornerRadius">8</attr>
    </style>
</styles>

最后需要在程序初始化的地方加载全局样式表,如下:

    NSString* path = [[NSBundle mainBundle]pathForResource:@"system" ofType:@"style"];
    [[FlexStyleMgr instance]loadClassStyle:path];
  • class标签中的样式同时支持布局属性和视图属性,可以同时在class标签中指定多个样式,中间用英文逗号分隔
  • 在layout和attr中指定的属性优先级高于class中的样式优先级
  • 如果视图元素没有指定class标签,则自动使用与类名同名的样式,样式不支持继承,也就是基类中的样式不会被子类 自动继承,需要在子类的样式中明确指定对应样式