YYPOST群发软件 发表于 2025-8-6 08:02:38

AIWROK软件苹果IOS里的UI-输入框类[Input]方法小结

AIWROK软件苹果IOS里的UI-输入框类方法小结
//🍎UI-输入框类方法方法小结,交流QQ群711841924

//第一个方法:📌setText 设置输入框文本


var input = new Input();
input.setText("Hello"); // 设置输入框文本为Hello



//第二个方法:📌getText 获取输入框文本


var input = new Input();
string currentText = input.getText(); // 获取输入框的文本内容



//第三个方法:📌setlD设置控件ID


var input = new Input();
input.setID("input123");
//读取使用
config.getConfig("input123");



//第四个方法:📌setDefultText 设置默认值

var input = new Input();
input.setID("输入框1")
input.setDefultText("Hello"); // 设置输入框文本为Hello



//第五个方法:📌setTextColor设置文本颜色


var input = new Input();
input.setTextColor(255, 0, 0); // 设置文本颜色为红色




//第六个方法:📌setFontSize设置字体大小


var input = new Input();
input.setFontSize(14); // 设置字体大小为14



//第七个方法:📌setBackgroundColor 设置背景颜色

var input = new Input();
input.setBackgroundColor(0, 255, 0); // 设置背景颜色为绿色





//第八个方法:📌setWidth设置输入框宽度



var input = new Input();
input.setWidth(300); // 设置输入框宽度为300



//第九个方法:📌setHeight 设置输入框高度


var input = new Input();
input.setHeight(40); // 设置输入框高度为40



//第十个方法:📌setPlaceholder 设置占位符文本

var input = new Input();
input.setPlaceholder("请输入内容"); // 设置占位符文本为'请输入内容'



//第十一个方法:📌setTextAlignment 设置文本对齐方式

var input = new Input();
input.setTextAlignment("center"); // 设置文本对齐方式为居中


//第十二个方法:📌setlnputStyle设置输入框样式


var input = new Input();
input.setInputStyle(true); // 设置输入框样式为底部线条

📌setText 设置输入框文本
类别
详情说明

方法功能
设置输入框的显示文本

方法签名
Void setText(String text)

返回值
Void

参数
-String text
:要设置的输入框文本内容

案例
var input = new Input();
input.setText("Hello"); // 设置输入框文本为Hello

📌getText 获取输入框文本
类别详情说明
方法功能获取当前输入框的文本内容
方法签名String getText()
返回值String
参数无
案例var input = new Input();string currentText = input.getText(); // 获取输入框的文本内容

📌setlD设置控件ID
类别详情说明
方法功能设置控件 ID,设置后可自动保存配置信息
方法签名Void setID(String id)
返回值Void
参数- String id:要设置的控件 ID
案例var input = new Input();input.setID("input123");//读取使用config.getConfig("input123");
📌setDefultText 设置默认值
类别详情说明
方法功能设置输入框的默认显示文本
方法签名Void setDefaultText(String text)
返回值Void
参数- String text:要设置的输入框默认文本内容
案例var input = new Input();input.setID("输入框1")input.setDefultText("Hello"); // 设置输入框文本为Hello
📌setTextColor设置文本颜色
类别详情说明
方法功能设置输入框文本的颜色
方法签名Void setTextColor(Int32 red, Int32 green, Int32 blue)
返回值Void
参数- Int32 red:红色分量(通常取值范围 0~255)
- Int32 green:绿色分量(通常取值范围 0~255)
- Int32 blue:蓝色分量(通常取值范围 0~255)
案例var input = new Input();input.setTextColor(255, 0, 0); // 设置文本颜色为红色
📌setFontSize设置字体大小
类别详情说明
方法功能设置输入框中文本的字体大小
方法签名Void setFontSize(Int32 size)
返回值Void
参数- Int32 size:要设置的字体大小
案例var input = new Input();input.setFontSize(14); // 设置字体大小为14
📌setBackgroundColor 设置背景颜色
类别详情说明
方法功能设置输入框的背景颜色
方法签名Void setBackgroundColor(Int32 red, Int32 green, Int32 blue)
返回值Void
参数- Int32 red:红色分量(通常取值范围 0~255)
- Int32 green:绿色分量(通常取值范围 0~255)
- Int32 blue:蓝色分量(通常取值范围 0~255)
案例var input = new Input();input.setBackgroundColor(0, 255, 0); // 设置背景颜色为绿色
📌setWidth设置输入框宽度
类别详情说明
方法功能设置输入框的宽度
方法签名Void setWidth(Int32 width)
返回值Void
参数- Int32 width:要设置的输入框宽度
案例var input = new Input();input.setWidth(300); // 设置输入框宽度为300
📌setHeight 设置输入框高度
类别详情说明
方法功能设置输入框的高度
方法签名Void setHeight(Int32 height)
返回值Void
参数- Int32 height:要设置的输入框高度
案例var input = new Input();input.setHeight(40); // 设置输入框高度为40
📌setPlaceholder 设置占位符文本
类别详情说明
方法功能设置输入框的占位符文本
方法签名Void setPlaceholder(String text)
返回值Void
参数- String text:要设置的占位符文本内容
案例var input = new Input();input.setPlaceholder("请输入内容"); // 设置占位符文本为'请输入内容'
📌setTextAlignment 设置文本对齐方式
类别详情说明
方法功能设置输入框中文字的对齐方式
方法签名Void setTextAlignment(String alignment)
返回值Void
参数- String alignment:文本对齐方式(如 center、left、right 等可选值)
案例var input = new Input();input.setTextAlignment("center"); // 设置文本对齐方式为居中
📌setlnputStyle设置输入框样式
类别详情说明
方法功能设置输入框的显示文本
方法签名Void setText(String text)
返回值Void
参数- String text:要设置的输入框文本内容
案例var input = new Input();input.setInputStyle(true); // 设置输入框样式为底部线条
完整案例:// 🔨UI-输入框类方法完整示例
// 🍎UI-输入框类方法小结,交流QQ群711841924

printl("=== Input控件方法完整示例 ===");

var vc = new IOSView();
vc.show(() => {
    printl("Input示例界面已加载");
   
    // 获取当前视图
    var view = vc.getView();
   
    // 创建主容器
    var mainContainer = new Vertical();
    mainContainer.setSpacing(15);
    mainContainer.setBackgroundColor(245, 245, 245);
   
    // 标题区域
    var titleContainer = new Vertical();
    titleContainer.setAlignment("center");
    titleContainer.setSpacing(5);
    titleContainer.setBackgroundColor(0, 122, 255);
   
    var titleLabel = new Label();
    titleLabel.setText("Input控件演示");
    titleLabel.setFontSize(20.0);
    titleLabel.setTextColor(255, 255, 255);
    titleLabel.setTextAlignment("center");
   
    var subtitleLabel = new Label();
    subtitleLabel.setText("输入框控件的使用方法");
    subtitleLabel.setFontSize(14.0);
    subtitleLabel.setTextColor(255, 255, 255);
    subtitleLabel.setTextAlignment("center");
   
    titleContainer.addView(titleLabel);
    titleContainer.addView(subtitleLabel);
    mainContainer.addView(titleContainer);
   
    // Input方法演示区域
    var demoContainer = new Vertical();
    demoContainer.setBackgroundColor(255, 255, 255);
    demoContainer.setSpacing(15);
   
    var demoTitle = new Label();
    demoTitle.setText("Input控件功能演示");
    demoTitle.setFontSize(16.0);
    demoTitle.setTextColor(0, 0, 0);
    demoTitle.setTextAlignment("center");
    demoContainer.addView(demoTitle);
   
    // 第一个方法:setText 设置输入框文本
    var setTextDemo = new Vertical();
    setTextDemo.setSpacing(5);
   
    var setTextLabel = new Label();
    setTextLabel.setText("📌 setText 设置输入框文本");
    setTextLabel.setFontSize(14.0);
    setTextLabel.setTextColor(0, 122, 255);
    setTextDemo.addView(setTextLabel);
   
    var setInput = new Input();
    setInput.setText("Hello"); // 设置输入框文本为Hello
    setInput.setWidth(250);
    setInput.setHeight(40);
    setInput.setBackgroundColor(240, 240, 240);
   
    setTextDemo.addView(setInput);
    demoContainer.addView(setTextDemo);
   
    // 第二个方法:getText 获取输入框文本
    var getTextDemo = new Vertical();
    getTextDemo.setSpacing(5);
   
    var getTextLabel = new Label();
    getTextLabel.setText("📌 getText 获取输入框文本");
    getTextLabel.setFontSize(14.0);
    getTextLabel.setTextColor(0, 122, 255);
    getTextDemo.addView(getTextLabel);
   
    var getInput = new Input();
    getInput.setPlaceholder("请输入内容");
    getInput.setWidth(250);
    getInput.setHeight(40);
    getInput.setBackgroundColor(240, 240, 240);
   
    var getButton = new Button();
    getButton.setText("获取文本");
    getButton.setColor(52, 199, 89);
    getButton.setTextColor(255, 255, 255);
    getButton.setWidth(80);
    getButton.setHeight(40);
   
    getButton.onClick(() => {
      var currentText = getInput.getText(); // 获取输入框的文本内容
      printl("输入框内容: " + currentText);
      
      var resultLabel = new Label();
      resultLabel.setText("获取到: " + currentText);
      resultLabel.setFontSize(12.0);
      resultLabel.setTextColor(52, 199, 89);
      getTextDemo.addView(resultLabel);
    });
   
    var getTextContainer = new Horizontal();
    getTextContainer.setSpacing(10);
    getTextContainer.addView(getInput);
    getTextContainer.addView(getButton);
   
    getTextDemo.addView(getTextContainer);
    demoContainer.addView(getTextDemo);
   
    // 第三个方法和第四个方法:setID 和 setDefultText
    var idDefaultDemo = new Vertical();
    idDefaultDemo.setSpacing(5);
   
    var idDefaultLabel = new Label();
    idDefaultLabel.setText("📌 setID 和 setDefultText");
    idDefaultLabel.setFontSize(14.0);
    idDefaultLabel.setTextColor(0, 122, 255);
    idDefaultDemo.addView(idDefaultLabel);
   
    var idInput = new Input();
    idInput.setID("输入框1");
    idInput.setDefultText("Hello"); // 设置输入框默认文本为Hello
    idInput.setWidth(250);
    idInput.setHeight(40);
    idInput.setBackgroundColor(240, 240, 240);
   
    var idButton = new Button();
    idButton.setText("读取配置");
    idButton.setColor(255, 149, 0);
    idButton.setTextColor(255, 255, 255);
    idButton.setWidth(80);
    idButton.setHeight(40);
   
    idButton.onClick(() => {
      var savedConfig = config.getConfig("输入框1");
      printl("保存的配置: " + savedConfig);
      
      var resultLabel = new Label();
      resultLabel.setText("配置值: " + savedConfig);
      resultLabel.setFontSize(12.0);
      resultLabel.setTextColor(255, 149, 0);
      idDefaultDemo.addView(resultLabel);
    });
   
    var idContainer = new Horizontal();
    idContainer.setSpacing(10);
    idContainer.addView(idInput);
    idContainer.addView(idButton);
   
    idDefaultDemo.addView(idContainer);
    demoContainer.addView(idDefaultDemo);
   
    // 第五个方法:setTextColor设置文本颜色
    var textColorDemo = new Vertical();
    textColorDemo.setSpacing(5);
   
    var textColorLabel = new Label();
    textColorLabel.setText("📌 setTextColor设置文本颜色");
    textColorLabel.setFontSize(14.0);
    textColorLabel.setTextColor(0, 122, 255);
    textColorDemo.addView(textColorLabel);
   
    var colorInput = new Input();
    colorInput.setPlaceholder("红色文本输入框");
    colorInput.setTextColor(255, 0, 0); // 设置文本颜色为红色
    colorInput.setWidth(250);
    colorInput.setHeight(40);
    colorInput.setBackgroundColor(240, 240, 240);
   
    textColorDemo.addView(colorInput);
    demoContainer.addView(textColorDemo);
   
    // 第六个方法:setFontSize设置字体大小
    var fontSizeDemo = new Vertical();
    fontSizeDemo.setSpacing(5);
   
    var fontSizeLabel = new Label();
    fontSizeLabel.setText("📌 setFontSize设置字体大小");
    fontSizeLabel.setFontSize(14.0);
    fontSizeLabel.setTextColor(0, 122, 255);
    fontSizeDemo.addView(fontSizeLabel);
   
    var sizeInput = new Input();
    sizeInput.setPlaceholder("大字体输入框");
    sizeInput.setFontSize(18); // 设置字体大小为18
    sizeInput.setWidth(250);
    sizeInput.setHeight(40);
    sizeInput.setBackgroundColor(240, 240, 240);
   
    fontSizeDemo.addView(sizeInput);
    demoContainer.addView(fontSizeDemo);
   
    // 第七个方法:setBackgroundColor 设置背景颜色
    var bgColorDemo = new Vertical();
    bgColorDemo.setSpacing(5);
   
    var bgColorLabel = new Label();
    bgColorLabel.setText("📌 setBackgroundColor设置背景颜色");
    bgColorLabel.setFontSize(14.0);
    bgColorLabel.setTextColor(0, 122, 255);
    bgColorDemo.addView(bgColorLabel);
   
    var bgInput = new Input();
    bgInput.setPlaceholder("绿色背景输入框");
    bgInput.setBackgroundColor(144, 238, 144); // 设置背景颜色为浅绿色
    bgInput.setWidth(250);
    bgInput.setHeight(40);
   
    bgColorDemo.addView(bgInput);
    demoContainer.addView(bgColorDemo);
   
    // 第八个和第九个方法:setWidth 和 setHeight
    var sizeDemo = new Vertical();
    sizeDemo.setSpacing(5);
   
    var sizeLabel = new Label();
    sizeLabel.setText("📌 setWidth 和 setHeight");
    sizeLabel.setFontSize(14.0);
    sizeLabel.setTextColor(0, 122, 255);
    sizeDemo.addView(sizeLabel);
   
    var sizeInput = new Input();
    sizeInput.setPlaceholder("自定义尺寸输入框");
    sizeInput.setWidth(300); // 设置输入框宽度为300
    sizeInput.setHeight(50); // 设置输入框高度为50
    sizeInput.setBackgroundColor(240, 240, 240);
   
    sizeDemo.addView(sizeInput);
    demoContainer.addView(sizeDemo);
   
    // 第十个方法:setPlaceholder 设置占位符文本
    var placeholderDemo = new Vertical();
    placeholderDemo.setSpacing(5);
   
    var placeholderLabel = new Label();
    placeholderLabel.setText("📌 setPlaceholder 设置占位符文本");
    placeholderLabel.setFontSize(14.0);
    placeholderLabel.setTextColor(0, 122, 255);
    placeholderDemo.addView(placeholderLabel);
   
    var placeholderInput = new Input();
    placeholderInput.setPlaceholder("请输入内容"); // 设置占位符文本为'请输入内容'
    placeholderInput.setWidth(250);
    placeholderInput.setHeight(40);
    placeholderInput.setBackgroundColor(240, 240, 240);
   
    placeholderDemo.addView(placeholderInput);
    demoContainer.addView(placeholderDemo);
   
    // 第十一个方法:setTextAlignment 设置文本对齐方式
    var alignmentDemo = new Vertical();
    alignmentDemo.setSpacing(5);
   
    var alignmentLabel = new Label();
    alignmentLabel.setText("📌 setTextAlignment 设置文本对齐方式");
    alignmentLabel.setFontSize(14.0);
    alignmentLabel.setTextColor(0, 122, 255);
    alignmentDemo.addView(alignmentLabel);
   
    var leftInput = new Input();
    leftInput.setPlaceholder("左对齐");
    leftInput.setTextAlignment("left"); // 设置文本对齐方式为左对齐
    leftInput.setWidth(250);
    leftInput.setHeight(40);
    leftInput.setBackgroundColor(240, 240, 240);
   
    var centerInput = new Input();
    centerInput.setPlaceholder("居中对齐");
    centerInput.setTextAlignment("center"); // 设置文本对齐方式为居中
    centerInput.setWidth(250);
    centerInput.setHeight(40);
    centerInput.setBackgroundColor(240, 240, 240);
   
    var rightInput = new Input();
    rightInput.setPlaceholder("右对齐");
    rightInput.setTextAlignment("right"); // 设置文本对齐方式为右对齐
    rightInput.setWidth(250);
    rightInput.setHeight(40);
    rightInput.setBackgroundColor(240, 240, 240);
   
    alignmentDemo.addView(leftInput);
    alignmentDemo.addView(centerInput);
    alignmentDemo.addView(rightInput);
    demoContainer.addView(alignmentDemo);
   
    // 第十二个方法:setInputStyle设置输入框样式
    var styleDemo = new Vertical();
    styleDemo.setSpacing(5);
   
    var styleLabel = new Label();
    styleLabel.setText("📌 setInputStyle设置输入框样式");
    styleLabel.setFontSize(14.0);
    styleLabel.setTextColor(0, 122, 255);
    styleDemo.addView(styleLabel);
   
    var styleInput = new Input();
    styleInput.setPlaceholder("底部线条样式");
    styleInput.setInputStyle(true); // 设置输入框样式为底部线条
    styleInput.setWidth(250);
    styleInput.setHeight(40);
   
    styleDemo.addView(styleInput);
    demoContainer.addView(styleDemo);
   
    mainContainer.addView(demoContainer);
   
    // 实际应用示例
    var applicationContainer = new Vertical();
    applicationContainer.setBackgroundColor(255, 255, 255);
    applicationContainer.setSpacing(15);
   
    var appTitle = new Label();
    appTitle.setText("Input实际应用示例");
    appTitle.setFontSize(16.0);
    appTitle.setTextColor(0, 0, 0);
    appTitle.setTextAlignment("center");
    applicationContainer.addView(appTitle);
   
    // 用户名输入
    var usernameContainer = new Vertical();
    usernameContainer.setSpacing(5);
   
    var usernameLabel = new Label();
    usernameLabel.setText("用户名:");
    usernameLabel.setFontSize(14.0);
    usernameLabel.setTextColor(0, 0, 0);
    usernameContainer.addView(usernameLabel);
   
    var usernameInput = new Input();
    usernameInput.setPlaceholder("请输入用户名");
    usernameInput.setWidth(250);
    usernameInput.setHeight(40);
    usernameInput.setBackgroundColor(240, 240, 240);
    usernameContainer.addView(usernameInput);
    applicationContainer.addView(usernameContainer);
   
    // 密码输入
    var passwordContainer = new Vertical();
    passwordContainer.setSpacing(5);
   
    var passwordLabel = new Label();
    passwordLabel.setText("密码:");
    passwordLabel.setFontSize(14.0);
    passwordLabel.setTextColor(0, 0, 0);
    passwordContainer.addView(passwordLabel);
   
    var passwordInput = new Input();
    passwordInput.setPlaceholder("请输入密码");
    passwordInput.setWidth(250);
    passwordInput.setHeight(40);
    passwordInput.setBackgroundColor(240, 240, 240);
    passwordInput.setInputStyle(true); // 底部线条样式
    passwordContainer.addView(passwordInput);
    applicationContainer.addView(passwordContainer);
   
    // 按钮区域
    var buttonContainer = new Horizontal();
    buttonContainer.setSpacing(10);
    buttonContainer.setAlignment("center");
   
    var submitBtn = new Button();
    submitBtn.setText("提交");
    submitBtn.setColor(0, 122, 255);
    submitBtn.setTextColor(255, 255, 255);
    submitBtn.setWidth(100);
    submitBtn.setHeight(40);
   
    submitBtn.onClick(() => {
      var username = usernameInput.getText();
      var password = passwordInput.getText();
      printl("用户名: " + username);
      printl("密码: " + password);
      
      var resultLabel = new Label();
      resultLabel.setText("提交成功!用户名: " + username);
      resultLabel.setFontSize(12.0);
      resultLabel.setTextColor(52, 199, 89);
      applicationContainer.addView(resultLabel);
    });
   
    var resetBtn = new Button();
    resetBtn.setText("重置");
    resetBtn.setColor(255, 149, 0);
    resetBtn.setTextColor(255, 255, 255);
    resetBtn.setWidth(100);
    resetBtn.setHeight(40);
   
    resetBtn.onClick(() => {
      usernameInput.setText("");
      passwordInput.setText("");
      printl("输入框已重置");
    });
   
    buttonContainer.addView(submitBtn);
    buttonContainer.addView(resetBtn);
    applicationContainer.addView(buttonContainer);
    mainContainer.addView(applicationContainer);
   
    // 控件信息区域
    var infoContainer = new Vertical();
    infoContainer.setBackgroundColor(236, 245, 255);
    infoContainer.setSpacing(8);
   
    var infoTitle = new Label();
    infoTitle.setText("ℹ️ Input控件说明");
    infoTitle.setFontSize(16.0);
    infoTitle.setTextColor(0, 122, 255);
    infoContainer.addView(infoTitle);
   
    var info1 = new Label();
    info1.setText("• Input控件用于接收用户输入");
    info1.setFontSize(12.0);
    info1.setTextColor(52, 58, 64);
    infoContainer.addView(info1);
   
    var info2 = new Label();
    info2.setText("• 支持文本设置、获取和样式定制");
    info2.setFontSize(12.0);
    info2.setTextColor(52, 58, 64);
    infoContainer.addView(info2);
   
    var info3 = new Label();
    info3.setText("• 可通过setID保存和读取配置");
    info3.setFontSize(12.0);
    info3.setTextColor(52, 58, 64);
    infoContainer.addView(info3);
   
    mainContainer.addView(infoContainer);
   
    // 底部按钮
    var bottomContainer = new Horizontal();
    bottomContainer.setSpacing(10);
    bottomContainer.setAlignment("center");
   
    var exitBtn = new Button();
    exitBtn.setText("退出示例");
    exitBtn.setColor(255, 59, 48);
    exitBtn.setTextColor(255, 255, 255);
    exitBtn.setHeight(40);
   
    exitBtn.onClick(() => {
      printl("退出按钮被点击");
      vc.dismiss();
    });
   
    bottomContainer.addView(exitBtn);
    mainContainer.addView(bottomContainer);
   
    // 添加到主视图
    view.addView(mainContainer);
   
    printl("Input示例界面构建完成");
});

printl("Input控件完整示例已启动");


页: [1]
查看完整版本: AIWROK软件苹果IOS里的UI-输入框类[Input]方法小结