cqbzzxx cqbzzxx
关注数: 20 粉丝数: 8 发帖数: 94 关注贴吧数: 4
刚写的codea中的输入文本框 刚刚看到一个同学在求输入框,写了个勉强能用的,需要的同学可以拿去封装成一个类。 我只是实现了功能,具体的完善谁有空谁改 function setup() -- Creates a button to clear the output touched = false myFrameCount = 0 --光标计数 textFieldX = 100 textFieldY = 600 textFieldWidth = 300 textFieldHeight = 30 end function draw() myFrameCount = myFrameCount +1 if (touchedInTextField(CurrentTouch.x,CurrentTouch.y)) then -- 判断是否点击到textField上 touched = true else touched = false end background(255) stroke(200) strokeWidth(2) if touched then fill(255) rect(textFieldX,textFieldY,textFieldWidth,textFieldHeight) -- 获取键盘输入内容 buffer = keyboardBuffer() pushStyle() textMode(CORNER) fill(0) text(buffer,textFieldX+3,textFieldY+4) popStyle() bufferLength = textSize(buffer) if(myFrameCount < 10) then pushStyle() stroke(0) strokeWidth(2) fill(0) line(textFieldX+3+bufferLength,textFieldY+3,textFieldX+3+bufferLength,textFieldY+27) --光标依据textField位置,文本长度定位 popStyle() else if (myFrameCount >30) then myFrameCount = 0 end end showKeyboard() else fill(230) rect(textFieldX,textFieldY,textFieldWidth,textFieldHeight) hideKeyboard() end end function touchedInTextField(x,y) if (x<textFieldX) then return false end if (x>textFieldX+textFieldWidth) then return false end if (y<textFieldY) then return false end if (y>textFieldY+textFieldHeight) then return falseend return true end
1 下一页