Label,Text Field和Combo Box来处理文本

一.使用Text Field

text field可以接受字符串和数字,可以通过下面的属性来获取值:

  • intValue:如果是字符串,则为0,如果浮点数,则去掉小数部分
  • floatValue或doubleValue:如果是字符串,则为0.0
  • stringValue:

除了标准的text field,Xcode也提供其它几种:

  • Text Field with Number Formatter
  • Secure Text Field
  • Search Field
  • Token Field

二.使用Combo Box

一个combo box基于NSComboBox类,可以展示一系列选项,并且允许用户进行输入。有两种方式来填充它的pop-up选项列表:使用属性检查面板或者外部的数据源(data source)

1.使用属性检查面板

代码如下:

AppDelegate.swift文件

import Cocoa

@NSApplicationMain
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Label文本手机上不显示处理 // Learn cc.Class: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html // Learn Attribute: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html // - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html // - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html cc.Class({ extends: cc.Component, properties: { nodeModule: cc.Node, nodeContainer: cc.Node, }, // LIFE-CYCLE CALLBACKS: // onLoad () {}, start () { }, // update (dt) {}, setLongText(longText){ // 界限值 const WORDS_COUNT = 100; let str = longText; let left = ''; do{ let index = str.indexOf('\n'); if(index == -1){ break; } left = left + str.substring(0, index); str = str.substring(index); while(str.length > 0 && str[0] == '\n'){ left = left + str[0]; str = str.substring(1); } if(left.length > WORDS_COUNT){ if(left.length >= 1&& left[left.length - 1] == '\n'){ left = left.substring(0, left.length -1); } this.addModule(left); left = ''; } }while(str.length > WORDS_COUNT); if(left != ''){ this.addModule(left); } if(str != ''){ this.addModule(str); } }, addModule(text){ cc.log('##text##', text); let node = cc.instantiate(this.nodeModule); node.active = true; node.getComponent(cc.Label).string = text; this.nodeContainer.addChild(node); }, onClick(){ this.setLongText(`

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值