控件:CheckBoxGroup 多选组合

又称作检查框,一共有 9 种属性:控件类型 type、控件 ID id、可选项标题 list、默认选中项编号 select、在可选项上显示图片 images、选项图片缩放 scale、单行控件显示数量 countperline、控件宽度 width、控件是否换行 nowrap

参数 类型 必填 说明 默认值
type string 控件类型:CheckBoxGroup -
id string 为控件指定 ID,可以理解为控件的名称,
在返回类型为 table 时将作为返回 table 中的 key,
控件ID 以 table 格式返回返回值时必填,否则无法获取返回值
-
list string 文字选项,多个可选项之间用英文半角逗号分割 -
select string 默认选项编号,允许填写一个或多个,填写多个时以 @ 分割。
序号从 0 开始,与可选项标题中的顺序保持一致
"0"
images string 图片选项,此属性可单独使用也可以和 list 属性同时使用,
多个图片资源用英文半角逗号分割
-
scale number 选项图片缩放比例,当 images 属性有效时可用此属性
设置图片资源缩放比例,范围 0 - 1
1
countperline number 单行控件显示数量,
引擎版本支持 iOS v3.00-157,
Android v2.3.6 及其以上版本
Android 默认 1 行显示 1 个,
iOS 控件总宽度超过屏幕宽度则堆积在一起
width number 控件宽度,当 showUI 全局属性 style 为 default 时,
如需将多个控件放入同一行显示,可用此属性调整控件宽度。
仅支持引擎版本 iOS v2.2.6, Android v1.2.4 及其以上版本
-1
nowrap number 控件是否换行,当此属性为 1 时,
将指定下一个控件不换行,用于将多个控件放入一行显示。
仅支持引擎版本 iOS v2.2.6, Android v1.2.5 及其以上版本
0
返回值 类型 说明
id 字符串 根据控件 ID 返回选择选项的内容,会返回类似于 "0@1" 的内容,
"0" 表示勾选了第一个选项,"1" 表示勾选了第二个选项,以此类推

函数用例

local ts = require("ts")
local cjson = ts.json
w,h = getScreenSize();
MyTable = {
    ["style"]  = "default",    
    ["width"] = w,          
    ["height"] = h,            
    ["cancelname"] = "取消",  
    ["okname"] = "开始", 
    ["title"] = "居中自定义字号",
    ["titlealign"] = "center",
    ["align"] = "center",
    ["titlesize"] = 12,  
    ["titles"] = "多选组合,第二页", 
    ["pagetype"]= "multi",  
    ["selpage"] = 1,   
    ["orient"] = 0, 
    ["btnbkcolor"] = "255,255,255",         
    ["bgcolor"] = "255,255,255",
    ["pagenumtype"] = "tab", 
    ["config"] = "showuiTest1.txt",  
    ["timer"] = 99,  
    ["rettype"] = "table",   
    pages            =
    {
        {
            {
                ["type"] = "Label",
                ["text"] = "点击右上角闹钟关闭倒计时↗",
                ["size"] = 20,
                ["align"] = "center",
                ["color"] = "255,0,0",
            },
            {
                ["type"] = "Label",
                ["align"] = "center",
                ["text"] = "多选组合-CheckBoxGroup",
                ["size"] = 20,
            },
            {   --必填,控件类型,多选组合
                ["type"] = "CheckBoxGroup",     
                -- 选填,无,控件 ID  以 table 格式返回返回值时必填,否则无法获取返回值
                ["id"] = "cbg",                             
                -- 必填,无 ,单选框内容
                ["list"] = "电影,读书,跑步,吃饭,"..
                "运动,睡觉,旅行,打豆豆,听歌",   
                -- 选填,0,默认选中项 ID
                ["select"] = "3@5@7",           
                ["scale"] = "0.4",  
                --选填,1,仅引擎版本支持 iOS v3.00-157 及 Android v2.3.6 及其以上版本
                ["countperline"]= "3",  
            },
        }
    }   
}
local MyJsonString = cjson.encode(MyTable);
UIret,values = showUI(MyJsonString)
if UIret == 1 then
    local cbg =  values.cbg 
    new  = cbg:split("@")
    for i=1,#new,1 do
        if new[i] == "0" then
            dialog("电影")
        elseif  new[i] == "1" then
            dialog("读书")
        elseif  new[i] == "2" then
            dialog("跑步")
        elseif  new[i] == "3" then
            dialog("吃饭")
        elseif  new[i] == "4" then
            dialog("运动")
        elseif  new[i] == "5" then
            dialog("睡觉")
        elseif  new[i] == "6" then
            dialog("旅行")
        elseif  new[i] == "7" then
            dialog("打豆豆")
        elseif  new[i] == "8" then
            dialog("听歌")
        end
    end
end
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""