 | |  |  | AIWROK苹果系统实例演示1标签类[Label]方法
- // 🔨🍎UI-标签类[Label]方法完整示例
- // UI-标签类[Label]方法小结,交流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控件方法演示程序启动");
复制代码
| |  | |  |
|