Hi,
I have a couple of problems with the native text field objects.
- I’m trying to create a placeholder text that gives the user instructions, such as “Search…”. After creating the newTextField i set its text property to “Search…”, which works fine. However, trying to clear that text in the began phase doesn’t work. How can I clear the placeholder text when the user hits the field for the first time?
local fieldHandler = function( event )
print( event.phase )
if "began" == event.phase then
-- do something on "keyboard has appeared" event
event.text="";
elseif "editing" == event.phase then
print (event.text);
elseif "ended" == event.phase then
-- This event is called when the user stops editing a field:
-- for example, when they touch a different field or keyboard focus goes away
-- Hide keyboard
native.setKeyboardFocus( nil )
elseif "submitted" == event.phase then
-- This event occurs when the user presses the "return" key
-- (if available) on the onscreen keyboard
-- Hide keyboard
native.setKeyboardFocus( nil )
end
end
local textBox = native.newTextField( 0, 0, 100, 30,fieldHandler )
textBox:setReferencePoint(display.CenterReferencePoint);
textBox.isEditable = true;
textBox.text = "Search...";
- What is the best practice to setting the text font for different screen sizes. The textfield looks OK on the iPhone screen but on an iPad, the field is too big for the text. (I’m using 320X480 and letterbox in the config.lua).
Thanks [import]uid: 33608 topic_id: 18483 reply_id: 318483[/import]
[import]uid: 52491 topic_id: 18483 reply_id: 71231[/import]