Total Pageviews

Tuesday, June 3, 2014

នេះជា Type TextBox របស់ Corona SDK

នេះជា Type TextBox របស់ Corona SDK
វាជា native text box ដែលអាច scrollable។ វាជា multi line input field សំរាប់បង្ហាញនៅ text based content។ សូមមើល native.newTextBox() សំរាប់ពត័មានលំអិត
ចំណាំះ វាមានតែលើ Device builds & Mac Simulator, មិនមាននៅលើ Windows Simulator
នេះជា Properties របស់វា
(Inherits properties from NativeDisplayObject)
 object.align
 ប្រើសំរាប់ Alignment នៃ text ដែលបង្ហាញនៅក្នុង text box។ វាអាចបញ្ចូលនៅ String ដូចខាងក្រោមះ
Left, center, right
សូមមើលកូដះ
local inputBox = native.newTextBox( 160, 240, 280, 140 )
inputBox.align = "center"

object.font
វាជា font របស់ ​text box។ វាអាចបញ្ចូលនៅ font object ដែលត្រឡប់ជា native.newFont()
សូមមើលកូដះ
Local myBox = native.newTextBox (160,240,280,140, fieldHandler)
local myBox.font = naitve.newFont (native.systemFontBold, 18)

object.hasBackground
ប្រើសំរាប់គ្រប់គ្រងថាតើ text box មាន opaque background ឬអត់។ តំលៃដើមគឺ true (opaque)
សូមមើលកូដះ
-- Draw red background
local r = display.newRect( 0, 0, 320, 480 )
r:setFillColor( 1, 0, 0 )

-- Text with transparent background
local t = native.newTextBox( 160, 240, 280, 140 )
t.font = native.newFont( "Helvetica-Bold", 16 )
t:setTextColor( 0.8, 0.8, 0.8 )
t.hasBackground = false
t.text = "Hello, world!"
object.isEditable
ប្រើសំរាប់គ្រប់គ្រងថាតើ text box គឺអាច editable។ តំលៃដើមគឺ false
សូមមើលកូដះ
local fieldHandler = function( event )
    print( event.phase )
    if "began" == event.phase then
        -- do something
    elseif "ended" == event.phase then
        -- do something
    elseif "submitted" == event.phase then
        -- do something
    end
end
local inputBox = native.newTextBox( 160, 240, 280, 140, fieldHandler )
inputBox.isEditable = true
                                                         
object.placeholder
នេះជា native text boxes អាចបង្ហាញនៅ optional placeholder text (nil by default) ។ វាអាចផ្តល់នៅ hint នៅអី្វដែលអ្នកប្រើអាចបញ្ចូលទៅក្នុង boxបើសិនជាបញ្ចូលនៅ placeholder string អាចបង្ហាញនៅ same style information (except the text color) ។ សំរាប់ placeholder មិនបង្ហាញនៅ actual text ដែលបានបញ្ចូលទៅកាន់ box ហើយមិនគិតអំពីទំហំរបស់ text box
សូមមើលកូដះ
local textBox = native.newTextBox( 160, 240, 280, 140 )
-- Optional placeholder (hint) for the text box
textBox.placeholder = "(description)"

object.size
វាជា font size របស់ text នៅក្នុង native text input box
សូមមើលកូដះ
local textBox = native.newTextBox( 160, 240, 280, 140 )
textBox.font = native.newFont( "Helvetica-Bold", 12 )
textBox:setTextColor( 0.8, 0.8, 0.8 )
textBox.hasBackground = false
textBox.text = "Hello World!"
-- change size property
textBox.size = 18


object.text
វាជា contents របស់ native text input box
សូមមើលកូដះ
local textBox = native.newTextBox( 160, 240, 280, 140 )
textBox.font = native.newFont( "Helvetica-Bold", 18 )
textBox:setTextColor( 0.8, 0.8, 0.8 )
textBox.alpha = 1.0
textBox.hasBackground = false
textBox.text = "Hello World!"


Methods
(Inherits methods from NativeDisplayObject)

object:setTextColor()
ប្រើសំរាប់ បញ្ចូលនៅ color of the text នៅក្នុង native text input box
Syntax: object:setTextColor (r,g,b)
Object:setTextColor (r,g,b,a)
R,g,b (តំរូវការ) វាជាចំនួនលេខដែលនៅចន្លោះ០នឹង​១ សំរាប់​ red, green​​ & blue channels
A(ជំរើស) វាជាចំនួនលេខដែលនៅចន្លោះ ០នឹង១ សំរាប់ alpha channel។​the default is 1
សូមមើលកូដះ
local textBox = native.newTextBox( 160, 240, 280, 140 )
textBox.font = native.newFont( "Helvetica-Bold", 18 )
textBox:setTextColor( 0.8, 0.8, 0.8 )
textBox.alpha = 1.0
textBox.hasBackground = false
textBox.text = "Hello World!"

object:setReturnKey()
ប្រើសំរាប់បញ្ចូលនៅ return key នៃ keyboard
Syntax: object:setReturnKey(key)
Key(តំរូវការ) វាជា String ដែលជា type name នៃ return button

Valid key Values
 •done(Android and iOS)
 •go(Android and iOS)
 •next(Android and iOS)
 •search(Android and iOS)
 •send(Android and iOS)
 •none(Android)
 •default(iOS)
 •join(iOS)
 •route(iOS)
 •emergencycall(iOS)

ចំណាំះ
Setting the return key to done causes no button to show up on the original Kindle Fire.

សូមមើលកូដះ
 local textBox = native.newTextBox( 160, 240, 280, 140 )
textBox.isEditable = true
textBox:setReturnKey("done")

No comments:

Post a Comment