B2B网络软件

标题: AIWROK软件IOS系统里的UI-标签类[Label]方法小结 [打印本页]

作者: YYPOST群发软件    时间: 昨天 07:05
标题: AIWROK软件IOS系统里的UI-标签类[Label]方法小结
AIWROK软件IOS系统里的UI-标签类[Label]方法小结
  1. //UI-标签类[Label]方法小结,交流QQ群711841924

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


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


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


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



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


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


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


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





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


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




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



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



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


  21. var label = new Label();
  22. 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)
完整示例方法例子:
  1. // 🔨🍎UI-标签类[Label]方法完整示例
  2. // UI-标签类[Label]方法小结,交流QQ群711841924

  3. // 创建 TabView
  4. var tab = new TabView();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  103.     // 标题
  104.     var title3 = new Label();
  105.     title3.setText("Label综合演示");
  106.     title3.setFontSize(20.0);
  107.     title3.setTextColor(0, 0, 150);
  108.     title3.setTextAlignment("center");
  109.     title3.setWidth(350);
  110.     title3.setHeight(50);
  111.     title3.setBackgroundColor(200, 230, 255);
  112.     comprehensivePage.addView(title3);

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

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

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

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

  151.     // 公共返回按钮
  152.     var btnBack = new Button();
  153.     btnBack.setText("返回");
  154.     btnBack.setColor(255, 0, 0);
  155.     btnBack.setTextColor(255, 255, 255);
  156.     btnBack.onClick(function() {
  157.         printl("返回键被点击");
  158.         tab.dismiss();
  159.     });

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

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

  167. printl("Label控件方法演示程序启动");
复制代码








欢迎光临 B2B网络软件 (http://bbs.niubt.cn/) Powered by Discuz! X3.2