IOS苹果系统创建具有现代H5视觉效果的界面

190

主题

190

回帖

1435

积分

管理员

积分
1435
IOS苹果系统创建具有现代H5视觉效果的界面

1.png 2.png

  1. // H5风格界面示例
  2. // 这个示例展示如何创建具有现代H5视觉效果的界面

  3. // ====================== 主视图 ======================
  4. function createH5StyleView() {
  5.     // 创建主视图
  6.     var vc = new IOSView();
  7.     vc.show(() => {
  8.         var view = vc.getView();
  9.         printl("H5风格界面已启动");
  10.         
  11.         // 创建标题栏
  12.         createHeader(view, vc);
  13.         
  14.         // 创建轮播图
  15.         createCarousel(view);
  16.         
  17.         // 创建功能卡片区域
  18.         createFeatureCards(view);
  19.         
  20.         // 创建表单区域
  21.         createFormSection(view);
  22.         
  23.         // 创建底部导航
  24.         createBottomNav(view, vc);
  25.     });
  26. }

  27. // ====================== 标题栏 ======================
  28. function createHeader(view, vc) {
  29.     var header = new Horizontal();
  30.     header.setSpacing(10);
  31.    
  32.     // 创建返回按钮
  33.     var backBtn = new Button();
  34.     backBtn.setText("<");
  35.     backBtn.setColor(255, 255, 255);
  36.     backBtn.setTextColor(0, 0, 0);
  37.     backBtn.setWidth(50);
  38.     backBtn.setHeight(50);
  39.     backBtn.onClick(() => {
  40.         vc.dismiss();
  41.     });
  42.     header.addView(backBtn);
  43.    
  44.     // 创建标题
  45.     var titleLabel = new Label();
  46.     titleLabel.setText("H5风格演示");
  47.     titleLabel.setTextColor(0, 0, 0);
  48.     titleLabel.setWidth(200);
  49.     header.addView(titleLabel);
  50.    
  51.     // 创建菜单按钮
  52.     var menuBtn = new Button();
  53.     menuBtn.setText("...");
  54.     menuBtn.setColor(255, 255, 255);
  55.     menuBtn.setTextColor(0, 0, 0);
  56.     menuBtn.setWidth(50);
  57.     menuBtn.setHeight(50);
  58.     menuBtn.onClick(() => {
  59.         printl("菜单按钮被点击");
  60.     });
  61.     header.addView(menuBtn);
  62.    
  63.     view.addView(header);
  64. }

  65. // ====================== 轮播图 ======================
  66. function createCarousel(view) {
  67.     var carousel = new Vertical();
  68.     carousel.setSpacing(10);
  69.    
  70.     // 创建轮播图内容(模拟)
  71.     var carouselContent = new Button();
  72.     carouselContent.setText("轮播图内容");
  73.     carouselContent.setColor(0, 150, 255);
  74.     carouselContent.setTextColor(255, 255, 255);
  75.     carouselContent.setWidth(380);
  76.     carouselContent.setHeight(180);
  77.     carousel.addView(carouselContent);
  78.    
  79.     // 创建轮播指示器
  80.     var indicators = new Horizontal();
  81.     indicators.setSpacing(5);
  82.    
  83.     // 添加指示器点
  84.     for (let i = 0; i < 3; i++) {
  85.         var dot = new Button();
  86.         dot.setWidth(10);
  87.         dot.setHeight(10);
  88.         dot.setColor(i === 0 ? 0 : 150, i === 1 ? 150 : 0, 255);
  89.         dot.onClick(() => {
  90.             printl("切换到轮播图第" + (i+1) + "页");
  91.         });
  92.         indicators.addView(dot);
  93.     }
  94.    
  95.     carousel.addView(indicators);
  96.    
  97.     view.addView(carousel);
  98. }

  99. // ====================== 功能卡片 ======================
  100. function createFeatureCards(view) {
  101.     var cardsContainer = new Vertical();
  102.     cardsContainer.setSpacing(10);
  103.    
  104.     // 创建卡片标题
  105.     var cardsTitle = new Label();
  106.     cardsTitle.setText("功能模块");
  107.     cardsTitle.setTextColor(0, 0, 0);
  108.     cardsTitle.setWidth(400);
  109.     cardsContainer.addView(cardsTitle);
  110.    
  111.     // 创建第一行卡片
  112.     var row1 = new Horizontal();
  113.     row1.setSpacing(10);
  114.    
  115.     // 卡片1
  116.     var card1Button = createFeatureCard("数据统计", 255, 99, 71);
  117.     card1Button.onClick(() => {
  118.         printl("点击了数据统计卡片");
  119.     });
  120.     row1.addView(card1Button);
  121.    
  122.     // 卡片2
  123.     var card2Button = createFeatureCard("设置", 65, 105, 225);
  124.     card2Button.onClick(() => {
  125.         printl("点击了设置卡片");
  126.     });
  127.     row1.addView(card2Button);
  128.    
  129.     // 创建第二行卡片
  130.     var row2 = new Horizontal();
  131.     row2.setSpacing(10);
  132.    
  133.     // 卡片3
  134.     var card3Button = createFeatureCard("帮助中心", 0, 128, 0);
  135.     card3Button.onClick(() => {
  136.         printl("点击了帮助中心卡片");
  137.     });
  138.     row2.addView(card3Button);
  139.    
  140.     // 卡片4
  141.     var card4Button = createFeatureCard("关于我们", 165, 42, 42);
  142.     card4Button.onClick(() => {
  143.         printl("点击了关于我们卡片");
  144.     });
  145.     row2.addView(card4Button);
  146.    
  147.     cardsContainer.addView(row1);
  148.     cardsContainer.addView(row2);
  149.    
  150.     view.addView(cardsContainer);
  151. }

  152. // ====================== 创建功能卡片 ======================
  153. function createFeatureCard(title, r, g, b) {
  154.     // 修复错误:直接创建一个带背景色的按钮作为卡片
  155.     var cardButton = new Button();
  156.     cardButton.setText(title);
  157.     cardButton.setColor(r, g, b);
  158.     cardButton.setTextColor(255, 255, 255);
  159.     cardButton.setWidth(150);
  160.     cardButton.setHeight(100);
  161.    
  162.     return cardButton;
  163. }

  164. // ====================== 表单区域 ======================
  165. function createFormSection(view) {
  166.     var formContainer = new Vertical();
  167.     formContainer.setSpacing(10);
  168.    
  169.     // 表单标题
  170.     var formTitle = new Label();
  171.     formTitle.setText("用户反馈");
  172.     formTitle.setTextColor(0, 0, 0);
  173.     formContainer.addView(formTitle);
  174.    
  175.     // 输入框1
  176.     var inputName = new Input();
  177.     // 修复拼写错误: setDefultText -> setPlaceholder
  178.     inputName.setPlaceholder("您的姓名");
  179.     inputName.setWidth(360);
  180.     inputName.setHeight(40);
  181.     formContainer.addView(inputName);
  182.    
  183.     // 输入框2
  184.     var inputEmail = new Input();
  185.     // 修复错误: 应该设置inputEmail而不是inputName
  186.     inputEmail.setPlaceholder("您的邮箱");
  187.     inputEmail.setWidth(360);
  188.     inputEmail.setHeight(40);
  189.     formContainer.addView(inputEmail);
  190.    
  191.     // 单选按钮组
  192.     var radioGroup = new RadioButtonGroup();
  193.     radioGroup.setID("feedbackType");
  194.    
  195.     var radio1 = new RadioButton();
  196.     radio1.setText("功能建议");
  197.     radio1.setGroup(radioGroup);
  198.    
  199.     var radio2 = new RadioButton();
  200.     radio2.setText("问题反馈");
  201.     radio2.setGroup(radioGroup);
  202.    
  203.     var radio3 = new RadioButton();
  204.     radio3.setText("其他");
  205.     radio3.setGroup(radioGroup);
  206.    
  207.     formContainer.addView(radio1);
  208.     formContainer.addView(radio2);
  209.     formContainer.addView(radio3);
  210.    
  211.     // 提交按钮
  212.     var submitBtn = new Button();
  213.     submitBtn.setText("提交反馈");
  214.     submitBtn.setColor(0, 150, 255);
  215.     submitBtn.setTextColor(255, 255, 255);
  216.     submitBtn.setWidth(360);
  217.     submitBtn.setHeight(50);
  218.     submitBtn.onClick(() => {
  219.         printl("反馈已提交");
  220.     });
  221.     formContainer.addView(submitBtn);
  222.    
  223.     view.addView(formContainer);
  224. }

  225. // ====================== 底部导航 ======================
  226. function createBottomNav(view, vc) {
  227.     var bottomNav = new Horizontal();
  228.     bottomNav.setSpacing(10);
  229.    
  230.     // 首页按钮
  231.     var homeBtn = new Button();
  232.     homeBtn.setText("首页");
  233.     homeBtn.setColor(0, 150, 255);
  234.     homeBtn.setTextColor(255, 255, 255);
  235.     homeBtn.onClick(() => {
  236.         printl("点击了首页");
  237.     });
  238.     bottomNav.addView(homeBtn);
  239.    
  240.     // 消息按钮
  241.     var messageBtn = new Button();
  242.     messageBtn.setText("消息");
  243.     messageBtn.setColor(128, 128, 128);
  244.     messageBtn.setTextColor(255, 255, 255);
  245.     messageBtn.onClick(() => {
  246.         printl("点击了消息");
  247.     });
  248.     bottomNav.addView(messageBtn);
  249.    
  250.     // 发现按钮
  251.     var discoverBtn = new Button();
  252.     discoverBtn.setText("发现");
  253.     discoverBtn.setColor(128, 128, 128);
  254.     discoverBtn.setTextColor(255, 255, 255);
  255.     discoverBtn.onClick(() => {
  256.         printl("点击了发现");
  257.     });
  258.     bottomNav.addView(discoverBtn);
  259.    
  260.     // 我的按钮
  261.     var profileBtn = new Button();
  262.     profileBtn.setText("我的");
  263.     profileBtn.setColor(128, 128, 128);
  264.     profileBtn.setTextColor(255, 255, 255);
  265.     profileBtn.onClick(() => {
  266.         printl("点击了我的");
  267.     });
  268.     bottomNav.addView(profileBtn);
  269.    
  270.     view.addView(bottomNav);
  271. }

  272. // ====================== 启动应用 ======================
  273. createH5StyleView();
复制代码


举报 回复