Page 1 of 1

Adding native controls

Posted: Wed Mar 16, 2016 2:56 am
by Opaquer
Hey everyone

I'm currently making an app for work, and at the moment it's going to be for iOS. Now, I've made all the fields and buttons and everything, but there's a slight issue. I didn't know about native controls until the other day! Since they're infinitely better than just a text field, I want to convert all my current text fields to native text controls. The only issue is that I don't know how to convert each existing text field to a native one. Obviously I could just go through and add a bunch of mobileControlCreate messages in, but that seems very time consuming, and seems like a lot of effort. I've read places about TMTools and MobGUI, but MobGUI doesn't look like it's in development anymore, and TMTools apparently only works for LC version 7, and I'm using version 8 :(

So is there any way to get the native controls to work without a lot of effort :)?

Thanks in advanced

Re: Adding native controls

Posted: Wed Mar 16, 2016 6:14 pm
by quailcreek
Here's some code I picked up on the forum. Been using it ever since. I create a rectangular graphic and name it accordingly, to define pRect. Use your imagination as to how fancy you want the native control to look.
TMControls2 does work on LC 8.

Code: Select all

on OpenCard
   if environment() is not "mobile" then exit OpenCard

   --inputCre pName, pKind, pRect, pAutoClear, pAutoFit, pAutoCap, pAutoCorrect, pKeyboardType, pReturnKey, pBackgroundColor, ptextAlign

   inputCreator "Paid", "input", "FigurePrice", "TRUE", "TRUE", "Words", "default", "decimal","Next",,"center"
   inputCreator "Shipping", "input", "Shipping", "TRUE", "TRUE", "Words", "default", "decimal","Next",,"center"
   inputCreator "Notes", "multiline", "FigureNotes", "TRUE", "TRUE", "sentences", "default", "default","default", "0,0,0,0","left"
end OpenCard

on closeCard
   if environment() is not "mobile" then exit closeCard
   put mobileControls() into tOpenControls
   repeat for each line N in tOpenControls
      mobileControlDelete N
   end repeat
end closeCard


on inputCreator pName, pKind, pRect, pAutoClear, pAutoFit, pAutoCap, pAutoCorrect, pKeyboardType, pReturnKey, pBackgroundColor, ptextAlign
   mobileControlCreate pKind, pName
   mobileControlSet pName, "visible", true
   mobileControlSet pName, "rect", the rect of grc pRect
   mobileControlSet pName, "opaque", false
   mobileControlSet pName, "autoFit", pAutoFit
   mobileControlSet pName, "autoClear", pAutoClear
   mobileControlSet pName, "autoCapitalizationType", pAutoCap
   mobileControlSet pName, "autoCorrectionType", pAutoCorrect
   mobileControlSet pName, "keyboardType", pKeyboardType
   mobileControlSet pName, "returnKeyType", pReturnKey
   mobileControlSet pName, "clearButtonMode", "while editing"
   mobileControlSet pName, "borderStyle", "none"
   mobileControlSet pName, "fontName", "Helvetica"
   mobileControlSet pName, "textColor", "0,0,0"
   mobileControlSet pName, "backgroundColor", pBackgroundColor
   mobileControlSet pName, "textAlign", ptextAlign
   
   if machine() contains "ipad" then
      mobilecontrolSet pName, "fontSize", 26
   else if machine() contains "iPhone" then
      mobilecontrolSet pName, "fontSize", 12
   else
      mobilecontrolSet pName, "fontSize", 12
   end if
end inputCreator

Re: Adding native controls

Posted: Thu Mar 17, 2016 5:28 am
by Opaquer
Hi Tom

Thanks for the code, it looks super helpful! The only issue now is going to be changing all the code to make it work :(. I do have one question - at the moment, I've got my app writing all the info into a text file, using something along the lines of "put field "Name"&" "&field"Last Name" into TotalName" etc. From what I understand, I can't do that with native controls, can I? I'd have to use mobileControlGet to get whatever is written in the control, right?

Native controls seem like a bit of a pain to get going :(

Re: Adding native controls

Posted: Thu Mar 17, 2016 3:51 pm
by quailcreek
It works pretty much the same.

Code: Select all

put mobileControlGet (“Name”, "text") && mobileControlGet (“LastlName”, "text") into TotalName

Re: Adding native controls

Posted: Tue Mar 22, 2016 6:21 am
by Opaquer
Thanks for this Tom. I'm working on getting everything over. I do have one question. Since these aren't fields, can I activate them with things like openField? I've got some of them doing things when the user starts to type, but I've been using the openField command for them so far :P. Would those need changing, and how could I go about it without it being an actual field?

Re: Adding native controls

Posted: Tue Mar 22, 2016 5:20 pm
by quailcreek
No worries, glad to help.

Look up inputBeginEditing, inputEndEditing, inputTextChanged in the dictionary.