懒人精灵_动态UI_数字抽奖示例

[复制链接]
查看2476 | 回复8 | 2022-2-26 13:16:27 | 显示全部楼层 |阅读模式
使用懒人精灵IDE编写一个基于动态UI的数字抽奖示例.
数字抽奖.lua 文件源码

  1. function 添加数字(数值)
  2.     local 数字表 = {}
  3.    
  4.     for i=1,math.tointeger(数值) do
  5.         table.insert(数字表,i)
  6.     end
  7.     return 数字表
  8. end

  9. function 随机抽奖(总表)
  10. ui.setTextView("tvId3",">>>>>> 正在抽奖 <<<<<<")
  11. ui.setTextSize("tvId4",30)
  12.     for i=1,30 do
  13.         ui.setTextView("tvId4",string.format("%d",rnd(1,#总表)))
  14.         sleep(200)
  15.     end
  16.     ui.setTextView("tvId3",">>>>>> 中奖号码 <<<<<<")
  17.     ui.setTextColor("tvId4","#ffff0000")
  18.     ui.setTextSize("tvId4",50)
  19.     ui.setTextView("tvId4",string.format("%d",rnd(1,#总表)))
  20.    
  21. end

  22. function onClick()
  23.     print('控件点击属性')
  24.     local tabArr = ui.getData()
  25.     print(tabArr)
  26.     local 总数 = ui.getValue("editId1")
  27.     if tabArr.btnnId1 == '开始抽奖'then
  28.         local 数字总表 = 添加数字(总数)
  29.         随机抽奖(数字总表)
  30.     end
  31. end

  32. -- 创建一个布局,这文本框,输入框,按钮信息
  33. ui.newLayout("layout1",-1,-1)

  34. ui.setTitleText("layout1","抽奖系统")
  35. ui.addTextView("layout1","tvId1","请输入总人数")
  36. ui.addEditText("layout1","editId1","")
  37. ui.addButton("layout1","btnnId1","开始抽奖")

  38. ui.newRow("layout1","row1",-2,-2)
  39. ui.addTextView("layout1","tvId3",">>>>>> 准备抽奖 <<<<<<")
  40. ui.setTextSize("tvId3",30)
  41. ui.setTextColor("tvId3","#ffff0000")

  42. ui.setGravity("row1",17)
  43. ui.newRow("layout1","row2",-2,-2)
  44. ui.addTextView("layout1","tvId4","")
  45. ui.setGravity("row2",17)

  46. ui.setPadding("tvId4",10,50,10,10)
  47. -- 点击按钮执行 随机抽奖函数
  48. ui.setOnClick("btnnId1","onClick()")

  49. ui.show("layout1",false)





  50. sleep(1000000)
复制代码

运行结果图片:
QQ截图20220223111100.png


回复

使用道具 举报

xywl | 2022-3-1 13:15:38 | 显示全部楼层
占楼支持大佬
回复

使用道具 举报

cocohuang | 2022-3-2 19:17:37 | 显示全部楼层
支持占楼
回复

使用道具 举报

类人猿学院 | 2022-3-16 09:15:32 | 显示全部楼层
不错,顶下!
回复

使用道具 举报

718204413 | 2022-5-8 14:12:50 | 显示全部楼层

谢谢大佬分享 !
回复

使用道具 举报

zipo_1 | 2022-5-15 11:03:23 | 显示全部楼层
谢谢分享
回复

使用道具 举报

17084437121 | 2022-5-18 16:51:03 | 显示全部楼层
加油升级 提升权限和积分
回复

使用道具 举报

yy5202071314 | 2022-5-19 11:20:24 | 显示全部楼层
加油升级 提升权限和积分
回复

使用道具 举报

jzl6668 | 2022-5-19 19:24:34 | 显示全部楼层


谢谢大佬分享 !
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则