For all you wanting TextFields with transparency and more TextBox features, here is a workaround:
\*\*\* Code example for Single line TextBox input to enable TextField-like input with transparency and other features.
\*\*\* Only tested in Xcode simulator for iOS
labelFont = gameUI.newFontXP{ ios="Cantarell-Bold", android=native.systemFont } -- This is a free truetype font that I use in my game
-- Globals:
statLabel=nil
statText="Player"
textBox=nil
-- We start with defining the handle that is called when anything happens in the text box:
local function textHandle( getObj )
return function( event )
if ( "began" == event.phase ) then
-- Text field is active
elseif ( "ended" == event.phase ) or ( "submitted" == event.phase ) or ("editing"== event.phase) then
-- This event is called when the user stops editing or enters something in a field:
statText= tostring( getObj().text )
textreturn=string.find(statText,string.char(10),1) -- Look for "return" character
if textreturn~=nil then
-- user pressed return button, so remove "return" from text field (it should not be more than one line)
statText=string.gsub( statText, string.char(10), "" )
end
statLabel.text=statText
if statLabel.width\>600 then
-- new object too wide; have to limit text length to prevent dual line textbox
statText=string.sub(statText,1,string.len(statText)-1)
statLabel.text=statText
end
for m=1,string.len(statLabel.text) do
if string.find(statLabel.text, " ", -1)~=nil then
-- iOS centering of text disregards spaces after last character, so Corona text must also do this:
statLabel.text=string.sub(statLabel.text,1,string.len(statLabel.text)-1)
end
end
if textBox.text~=statText then
-- only update text box text if strictly necessary (will move cursor)
textBox.text = statText
end
if ("editing"~= event.phase) or textreturn~=nil then
-- if event was ended or submitted, or return pressed, remove focus from field..
native.setKeyboardFocus( nil )
end
end
end -- "return function()"
end
-- Then we set up the text box:
textBox = native.newTextBox( 11, 70+43, 620, 78
textBox:addEventListener( 'userInput',
function ()
return textBox
end ) )
textBox:setTextColor( 0, 0, 255, 255 )
textBox.hasBackground = false
textBox.align = "center" -- correct alignment/placement only shows up on device or Xcode, not Corona simulator
textBox.text = statText
textBox.font = native.newFont( "Cantarell-Bold", 20 ) -- This is a free truetype font that I use in my game
textBox.inputType = "default"
textBox.alpha = 0.5
textBox.isEditable = true
textBox.y = 70+82
-- This is optional: It puts a Corona text object beneath the iOS object; only shown as example. The reason to have this is that Corona objects can be made more appealing (shadowing, outlining, multicolor and so on..).
statLabel=display.newText(statText, display.contentWidth/2, 130, labelFont, 40 )
statLabel.x=statLabel.x-(statLabel.contentWidth/2)
statLabel:setTextColor( 255, 255, 255, 255 )
-- Note: text box text has a tendency to shift 1 pixels in some instances in comparison to corona text. You may want to use non-bold font for the text object to compensate for this.
This source code has been cut out from a larger program, so there may be typos. Please also note that the cursor will move to the end of the field if you edit the textbox text during typing (like removing non-allowed characters or alike).
Anyway, hope it helps someone!
Best,
Renato
Microingress Ltd [import]uid: 141323 topic_id: 24285 reply_id: 137502[/import]