控件:Edit 单行文本框

一共有 12 种属性:控件类型 type、控件 ID id、编辑框提示文本 prompt、编辑框默认内容 text、字体大小 size、对齐方式 align、垂直对齐方式 valign、字体颜色 color、键盘类型 kbtype、是否明文显示 secure、控件宽度 width、控件是否换行 nowrap

参数 类型 必填 说明 默认值
type string 控件类型:Edit -
id string 为控件指定 ID,可以理解为控件的名称,
在返回类型为 table 时将作为返回 table 中的 key,
控件ID 以 table 格式返回返回值时必填,否则无法获取返回值
-
prompt string 提示文字,编辑框中无任何内容时显示的底色文本 -
text string 默认文字,界面载入时已经存在于编辑框中的文本 -
size number 字号,如果不指定该属性,则默认值为 15 15
align string 水平对齐方式 ,默认左对齐。
可取值为:左对齐 left,右对齐 right,居中 center
"left"
valign string 垂直对齐方式,顶端对齐 top,
垂直居中 center,底部对齐 bottom,
默认垂直居中,仅支持 Androidv3.2.0、iOSv3.1.5 以及以上版本
"center"
color string 文字颜色,默认黑色(0,0,0)。使用 RGB 十进制数值,
以英文半角逗号分割
"0,0,0"
kbtype string 键盘类型,设置获取焦点时弹出的键盘类型,
默认为 number,number ascii default
default 仅支持 iOS 设备显示当前设备默认的键盘
"number"
secure boolean 是否明文显示,默认关闭,true - 非明文显示,false - 明文显示,
引擎版本仅支持 Android v3.1.3.1、专业版 iOS v3.0.8 及其以上版本
false
width number 控件宽度,当 showUI 全局属性 style 为 default 时,
如需将多个控件放入同一行显示,可用此属性调整控件宽度。
仅支持引擎版本 iOS v2.2.6, Android v1.2.4 及其以上版本。
-1 为自适应屏幕,0 为占用整行,
大于等于 1 按照数字设置宽度,不填默认占整行,
-1、0、及大于等于 1 参数仅支持
Androidv3.2.0、iOSv3.1.5 以及以上版本。
0
nowrap number 控件是否换行,当此属性为 1 时,
将指定下一个控件不换行,用于将多个控件放入一行显示。
仅支持引擎版本 iOS v2.2.6, Android v1.2.5 及其以上版本。
0
返回值 类型 说明
id 字符串 根据控件 ID 返回文本框的内容

函数用例

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"] = 12, 
                ["align"] = "left",          
                ["valign"] = "top", 
                ["color"] = "0,0,0",           
                ["width"] = -1,
                ["nowrap"] = 1,--下个控件不换行
            },
            {
                ["type"] = "Edit",               
                ["id"] = "year",                  
                ["prompt"] = "年",  
                ["text"] = "2014",     
                ["kbtype"] = "number",  
                ["color"] = "0,0,0",   
                ["size"] = 12,           
                ["align"] = "center",           
                ["valign"] = "top",   
                ["width"] = 180,
                ["nowrap"] = 1,--下个控件不换行
            },
            {
                ["type"] = "Label", 
                ["text"] = "年",        
                ["size"] = 12, 
                ["align"] = "left",          
                ["valign"] = "top", 
                ["color"] = "0,0,0",           
                ["width"] = -1,
                ["nowrap"] = 1,--下个控件不换行
            },
            {
                ["type"] = "Edit",               
                ["id"] = "month",                  
                ["prompt"] = "月",  
                ["text"] = "5",     
                ["kbtype"] = "number",  
                ["color"] = "0,0,0",   
                ["size"] = 12,           
                ["align"] = "center",--输入框文字水平对齐方式           
                ["valign"] = "top", --输入框垂直对齐方式  
                ["width"] = 120,
                ["nowrap"] = 1,--下个控件不换行
            },
            {
                ["type"] = "Label",            
                ["text"] = "月",        
                ["size"] = 12,                 
                ["align"] = "left",           
                ["valign"] = "top", 
                ["color"] = "0,0,0",    
                ["width"] = -1,
                ["nowrap"] = 1,--下个控件不换行
            },
            {
                ["type"] = "Edit",               
                ["id"] = "day",                  
                ["prompt"] = "日",  
                ["text"] = "1",     
                ["kbtype"] = "number",  
                ["color"] = "0,0,0",   
                ["size"] = 12,           
                ["align"] = "center",           
                ["valign"] = "top",   
                ["width"] = 120,
                ["nowrap"] = 1,--下个控件不换行
            },
            {
                ["type"] = "Label",        
                ["text"] = "日",        
                ["size"] = 12,                  
                ["align"] = "left",           
                ["valign"] = "top", 
                ["color"] = "0,0,0",           
                ["width"] = -1,
                --["nowrap"] = 1,
            },      
        }
    }   
}
local MyJsonString = cjson.encode(MyTable);
UIret,values = showUI(MyJsonString)
if UIret == 1 then
    local year =  values.year
    local month =  values.month
    local day =  values.day
    dialog("上线日期:"..year.." 年 "..month.." 月 "..day.." 日")
end

注意事项

  • width 为 -1 时根据文字长度显示控件宽度。
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""