YYPOST群发软件 发表于 4 天前

AIWROK软件IOS系统里的UI-标签类[Label]方法小结

AIWROK软件IOS系统里的UI-标签类方法小结
//UI-标签类方法小结,交流QQ群711841924

//第一个方法:setText设置标签文本


var label = new Label();
label.setText("Hello World");


//第二个方法:setTextColor设置文本颜色


var label = new Label();
label.setTextColor(1.0f, 0.0f, 0.0f); // 设置文本颜色为红色



//第三个方法:setFontSize设置字体大小


var label = new Label();
label.setFontSize(16.0f); // 设置字体大小为16


//第四个方法:setBackgroundColor设置背景颜色


var label = new Label();
label.setBackgroundColor(0, 255, 255); // 设置背景颜色为绿色





//第五个方法:setWidth 设置标签宽度


var label = new Label();
label.setWidth(200); // 设置标签宽度为200




//第六个方法:setHeight设置标签高度



var label = new Label();
label.setHeight(50); // 设置标签高度为50



//第七个方法:setTextAlignment设置文本对齐方式


var label = new Label();
label.setTextAlignment("center"); // 设置文本对齐方式为居中left center right
📌setText设置标签文本
类别详情说明
方法功能设置标签的显示文本
方法签名Void setText(String text)
返回值Void
参数- String text:要设置的标签文本
案例var label = new Label();label.setText("Hello World");
📌setTextColor 设置文本颜色
类别详情说明
方法功能设置文本的颜色
方法签名Void setTextColor(Single red, Single green, Single blue)
返回值Void
参数- Single red:红色分量
- Single green:绿色分量
- Single blue:蓝色分量
案例var label = new Label();label.setTextColor(1.0f, 0.0f, 0.0f); // 设置文本颜色为红色
📌setBackgroundColor设置背景颜色
类别详情说明
方法功能设置文本的颜色
方法签名Void setTextColor(Single red, Single green, Single blue)
返回值Void
参数- Single red:红色分量
- Single green:绿色分量
- Single blue:蓝色分量
案例var label = new Label();label.setTextColor(1.0f, 0.0f, 0.0f); // 设置文本颜色为红色
📌setFontSize设置字体大小
类别详情说明
方法功能设置文本的字体大小
方法签名Void setFontSize(Single size)
返回值Void
参数- Single size:字体大小参数
案例var label = new Label();label.setFontSize(16.0f); // 设置字体大小为16
📌setWidth 设置标签宽度
类别详情说明
方法功能设置标签的宽度
方法签名Void setWidth(Int32 width)
返回值Void
参数- Int32 width:要设置的标签宽度值
案例var label = new Label();label.setWidth(200); // 设置标签宽度为200
📌setHeight设置标签高度
类别详情说明
方法功能设置标签的高度
方法签名Void setHeight(Int32 height)
返回值Void
参数- Int32 height:要设置的标签高度值
案例var label = new Label();label.setHeight(50); // 设置标签高度为50
📌setTextAlignment设置文本对齐方式
类别详情说明
方法功能设置文本在标签内的对齐方式,可选值:left(左对齐)、center(居中对齐)、right(右对齐)
方法签名Void setTextAlignment(String alignment)
返回值Void
参数- String alignment:对齐方式,可选值为 left(左对齐)、center(居中对齐)、right(右对齐)
案例var label = new Label();label.setTextAlignment("center"); // 设置文本对齐方式为居中(可选值:left、center、right)
完整示例方法例子:// 🔨🍎UI-标签类方法完整示例
// UI-标签类方法小结,交流QQ群711841924

// 创建 TabView
var tab = new TabView();

// 设置标签页标题
tab.setTitles(["文本与颜色", "尺寸与对齐", "综合演示"]);

// 显示 TabView,并在加载完成后执行回调函数
tab.show(function() {
    printl("Label示例 TabView 显示完成");

    // ====================== 第一页:文本与颜色设置 ======================
    var textColorPage = new Vertical();
    textColorPage.setSpacing(15);
    textColorPage.setBackgroundColor(240, 240, 240);

    // 标题
    var title = new Label();
    title.setText("Label文本与颜色设置演示");
    title.setFontSize(18.0);
    title.setTextColor(0, 0, 0);
    textColorPage.addView(title);

    // 基本文本设置
    var basicText = new Label();
    basicText.setText("基本文本设置示例");
    textColorPage.addView(basicText);

    // 红色文本
    var redText = new Label();
    redText.setText("这是红色文本");
    redText.setTextColor(255, 0, 0); // 红色
    redText.setFontSize(16.0);
    textColorPage.addView(redText);

    // 绿色文本
    var greenText = new Label();
    greenText.setText("这是绿色文本");
    greenText.setTextColor(0, 255, 0); // 绿色
    greenText.setFontSize(14.0);
    textColorPage.addView(greenText);

    // 蓝色文本
    var blueText = new Label();
    blueText.setText("这是蓝色文本");
    blueText.setTextColor(0, 0, 255); // 蓝色
    blueText.setFontSize(12.0);
    textColorPage.addView(blueText);

    // 带背景色的文本
    var bgText = new Label();
    bgText.setText("带背景色的文本");
    bgText.setTextColor(255, 255, 255); // 白色文本
    bgText.setBackgroundColor(100, 100, 100); // 灰色背景
    textColorPage.addView(bgText);

    // ====================== 第二页:尺寸与对齐设置 ======================
    var sizeAlignPage = new Vertical();
    sizeAlignPage.setSpacing(20);
    sizeAlignPage.setBackgroundColor(245, 245, 220);

    // 标题
    var title2 = new Label();
    title2.setText("Label尺寸与对齐设置演示");
    title2.setFontSize(18.0);
    title2.setTextColor(0, 0, 0);
    sizeAlignPage.addView(title2);

    // 不同尺寸的文本
    var largeText = new Label();
    largeText.setText("大号字体 (20px)");
    largeText.setFontSize(20.0);
    largeText.setWidth(300);
    largeText.setHeight(40);
    sizeAlignPage.addView(largeText);

    var mediumText = new Label();
    mediumText.setText("中号字体 (16px)");
    mediumText.setFontSize(16.0);
    mediumText.setWidth(250);
    mediumText.setHeight(35);
    sizeAlignPage.addView(mediumText);

    var smallText = new Label();
    smallText.setText("小号字体 (12px)");
    smallText.setFontSize(12.0);
    smallText.setWidth(200);
    smallText.setHeight(30);
    sizeAlignPage.addView(smallText);

    // 不同对齐方式
    var leftAlign = new Label();
    leftAlign.setText("左对齐文本");
    leftAlign.setTextAlignment("left");
    leftAlign.setWidth(250);
    leftAlign.setHeight(30);
    leftAlign.setBackgroundColor(220, 220, 255);
    sizeAlignPage.addView(leftAlign);

    var centerAlign = new Label();
    centerAlign.setText("居中对齐文本");
    centerAlign.setTextAlignment("center");
    centerAlign.setWidth(250);
    centerAlign.setHeight(30);
    centerAlign.setBackgroundColor(220, 255, 220);
    sizeAlignPage.addView(centerAlign);

    var rightAlign = new Label();
    rightAlign.setText("右对齐文本");
    rightAlign.setTextAlignment("right");
    rightAlign.setWidth(250);
    rightAlign.setHeight(30);
    rightAlign.setBackgroundColor(255, 220, 220);
    sizeAlignPage.addView(rightAlign);

    // ====================== 第三页:综合演示 ======================
    var comprehensivePage = new Vertical();
    comprehensivePage.setSpacing(15);
    comprehensivePage.setBackgroundColor(255, 240, 240);

    // 标题
    var title3 = new Label();
    title3.setText("Label综合演示");
    title3.setFontSize(20.0);
    title3.setTextColor(0, 0, 150);
    title3.setTextAlignment("center");
    title3.setWidth(350);
    title3.setHeight(50);
    title3.setBackgroundColor(200, 230, 255);
    comprehensivePage.addView(title3);

    // 多种属性组合
    var combo1 = new Label();
    combo1.setText("大字体+红色+居中+背景色");
    combo1.setFontSize(18.0);
    combo1.setTextColor(200, 0, 0);
    combo1.setTextAlignment("center");
    combo1.setWidth(350);
    combo1.setHeight(45);
    combo1.setBackgroundColor(255, 230, 230);
    comprehensivePage.addView(combo1);

    var combo2 = new Label();
    combo2.setText("中字体+蓝色+右对齐+背景色");
    combo2.setFontSize(15.0);
    combo2.setTextColor(0, 0, 200);
    combo2.setTextAlignment("right");
    combo2.setWidth(350);
    combo2.setHeight(40);
    combo2.setBackgroundColor(230, 230, 255);
    comprehensivePage.addView(combo2);

    var combo3 = new Label();
    combo3.setText("小字体+绿色+左对齐+背景色");
    combo3.setFontSize(12.0);
    combo3.setTextColor(0, 150, 0);
    combo3.setTextAlignment("left");
    combo3.setWidth(350);
    combo3.setHeight(35);
    combo3.setBackgroundColor(230, 255, 230);
    comprehensivePage.addView(combo3);

    // 信息展示标签
    var infoLabel = new Label();
    infoLabel.setText("Label控件支持7种方法:\n1. setText - 设置文本\n2. setTextColor - 设置文本颜色\n3. setFontSize - 设置字体大小\n4. setBackgroundColor - 设置背景色\n5. setWidth - 设置宽度\n6. setHeight - 设置高度\n7. setTextAlignment - 设置文本对齐");
    infoLabel.setFontSize(12.0);
    infoLabel.setTextColor(50, 50, 50);
    infoLabel.setTextAlignment("left");
    infoLabel.setWidth(350);
    infoLabel.setHeight(150);
    infoLabel.setBackgroundColor(255, 255, 200);
    comprehensivePage.addView(infoLabel);

    // 公共返回按钮
    var btnBack = new Button();
    btnBack.setText("返回");
    btnBack.setColor(255, 0, 0);
    btnBack.setTextColor(255, 255, 255);
    btnBack.onClick(function() {
      printl("返回键被点击");
      tab.dismiss();
    });

    // 添加所有页面到TabView
    tab.addView(0, textColorPage);
    tab.addView(1, sizeAlignPage);
    tab.addView(2, comprehensivePage);
    tab.addView(3, btnBack);

    printl("Label示例视图添加完成");
});

printl("Label控件方法演示程序启动");


页: [1]
查看完整版本: AIWROK软件IOS系统里的UI-标签类[Label]方法小结