Total Pageviews

Tuesday, June 3, 2014

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

នេះជា Type TextFieldtex របស់ Corona SDK
វាជា native text field ដែលជា single line input field សំរាប់បង្ហាញនៅ text based content, សូមមើលនៅ native.newTextField()សំរាប់ពត័មានលំអិត
ចំណាំះ      
សំរាប់ Native text fields មានតែលើ device builds & Mac Simulator មិនមាននៅលើ Windows Simulator
នេះជា Properties របស់វា
object.align
វាប្រើសំរាប់ Alignment របស់ text ដែលបង្ហាញនៅ input text field វាអាចបញ្ចូលនៅ String ដូចខាងក្រោមះ left, center, right
សូមមើលកូដះ
local nameField = native.newTextField( 50, 150, 220, 36, handlerFunction )
nameField.align = "center"
                
object.font
វាជា Font នៃ text input field, ដែលត្រូវបញ្ចូលទៅកាន់ font object ជា returned តាមរយះ native.newFont()
សូមមើលកូដះ
local myField = native.newTextField( 10, 30, 180, 30, fieldHandler )
local myField.font = native.newFont( native.systemFontBold, 18 )    
         
                                     
object.hasBackground
វាប្រើសំរាប់គ្រប់គ្រង់ថាតើ text box មាន opaque background or not។ តំលៃដើម true (opaque)
សូមមើលកូដះ
-- Draw red background
local r = display.newRect( 0, 0, 320, 480 )
r:setFillColor( 1, 0, 0 )

-- Textfield, with transparent background
local t = native.newTextField( 30, 140, 260, 100 )
t.font = native.newFont( "Helvetica-Bold", 16 )
t:setTextColor( 0.8, 0.8, 0.8 )
t.hasBackground = false
t.text = "Hello, world!"



object.inputType
វាជា keyboard type របស់ native text input field។ ដែលតំលៃរបស់វាមាន
Default ជា default keyboard, ដែល supporting general text, numbers & punctuation
Number ជា numeric keypad
Decimal​ ជា keypad សំរាប់បញ្ចូលនៅចំនួន decimal value
Phone ជា keypad សំរាប់បញ្ចូលនៅចំនួនលេខទូរស័ព្ទ
url ជា keypad សំរាប់បញ្ចូលនៅ website URLs
email ជា keypad សំរាប់បញ្ចូលនៅ Email addresses
ចំណាំះ ដើម្បីបង្កើតនៅ Password entry field ត្រូវបញ្ចូលនៅ object.isSecure Boolean property
សូមមើលកូដះ
local numericField = native.newTextField( 50, 150, 220, 36, handlerFunction )
numericField.inputType = "number"
                
object.isSecure
វាជាការគ្រប់គ្រងថាតើ text នៅក្នុង field គឺ Obscured, e.g passwords, default is false
សូមមើលកូដះ
local passwordField = native.newTextField( 100, 50, 40, 30, inputListener )
passwordField.inputType = "number"
passwordField.isSecure = true

object.placeholder
សំរាប់ Native text fields អាចបង្ហាញនៅ optional placeholder text (nil, by default) វាអាចផ្តល់នៅ hint ដែលអ្នកប្រើអាចបញ្ចូលនៅក្នុង Field។ បើសិនជាបញ្ចូលវានៅ Placeholder string ដែលបង្ហាញនៅការប្រើប្រាស់ the same style information (except the text color) សំរាប់ placeholder មិនបង្ហាញនៅ actual text ដែលបានបញ្ចូលទៅក្នុង field ទេហើយមិន participate in determining the size of the text field
សូមមើលកូដះ
local numericField = native.newTextField( 150, 150, 220, 36 )
numericField.inputType = "number"
-- Optional placeholder (hint) for the text field
numericField.placeholder = "(phone number)"
numericField:addEventListener( "userInput", handlerFunction )

object.size
វាជា font size របស់ text នៅក្នុង native text input field
សូមមើលកូដះ
local field1 = native.newTextField( 50, 100, 100, 35 )
field1.align = "center"
field1.size = 32
field1:setTextColor( 1, 0.5, 0 )
field1.text = "Hello World!"

object.text
វាជា contents របស់ native text input field
សូមមើលកូដះ
local field1 = native.newTextField( 50, 100, 100, 35 )
field1.align = "center"
field1.size = 32
field1:setTextColor( 1, 0.5, 0 )
field1.text = "Hello World!"

Methods
(Inherits methods from NativeDisplayObject)
object:setTextColor()       
ប្រើសំរាប់បញ្ចូលនៅ Color របស់ text នៅក្នុង native text input field
Syntax: object:setTextColor (r,g,b)
Object:setTextColor(r,g,b,a)
R,g,b(តំរូវការ) វាជាចំនួនលេខដែលនៅតំលៃពី ០នឹង១ សំរាប់ red,green & blue channels
A(ជំរើស) វាជាចំនួនលេខដែលនៅចន្លោះ ០នឹង ១ សំរាប់ alpha channel default is 1
សូមមើលកូដះ
local field1 = native.newTextField( 50, 100, 100, 35 )
field1.align = "center"
field1.size = 32
field1:setTextColor( 1, 0.5, 0 )
field1.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 textField = native.newTextField( 30, 140, 260, 150 )
textField:setReturnKey("done")           


No comments:

Post a Comment