Label & keyboard input possible?

Is there a way to use the keyboard and add all keyboard input in a Label?

Of not possible, maybe it is possible to have a work-a-round for this and use a Textfield and place it out of the iOSView.
When the user touches the Label, you set focus to the Textfield so the keyboard is shown. Then put code in the Textchanged event to update the Label accordingly.
But how can you force the Textfield to be focused?

[quote=154331:@Christoph De Vocht]Is there a way to use the keyboard and add all keyboard input in a Label?

Of not possible, maybe it is possible to have a work-a-round for this and use a Textfield and place it out of the iOSView.
When the user touches the Label, you set focus to the Textfield so the keyboard is shown. Then put code in the Textchanged event to update the Label accordingly.
But how can you force the Textfield to be focused?[/quote]

I do something similar for my school letter cards application. On the “pick letter” view, I have a small textfield hidden under a rectangle for input, and setfocus to it using a declare in the wrapper, which displays the keyboard. There is also a Clearfocus function to hide the keyboard. https://forum.xojo.com/18171-xojoioswrapper

The user never sees the TextField. I use the TextChanged event into it to know which key has been tapped. You could do the same to copy the Text property into the label.

Thanks Michel, thats how I also thought about doing this. Will look at the declares asap !

BTW thank you for keeping XojoiOSWrapper uptodate.

BTW The main reason I need this is because the Textfield font cannot be made very big (max. 38 points).

Why not use a TextArea instead ?

Because I cannot force it be one line only. :slight_smile:

What about managing that in TextChanged ? Seems pretty straightforward …

Where did that limitation come from? It certianly isn’t a limit of iOS

I just tested the equivalent in and made a single character as large as the screen

OH… I think I see… XOJO forces the Textfield to a specific height… why do the restrict that? UITextField is not restricted to 31pixels in height

[quote=154424:@Dave S]Where did that limitation come from? It certianly isn’t a limit of iOS

I just tested the equivalent in and made a single character as large as the screen

OH… I think I see… XOJO forces the Textfield to a specific height… why do the restrict that? UITextField is not restricted to 31pixels in height[/quote]

Thank you Dave. This gave me the hint for the workaround. Even if the 31 pix limit should be reported as a bug, I think.

  • Drag a textarea to the view. Make it any size needed
  • In the Inspector, change the super to iOSTextField

Voilà ! Height can be managed by changing the Auto Layout height constraint.

Remember, UITextField and UITextArea (which are probably the underlying controls used by XOJO) have DIFFERENT supers to start with… they are not derived directly from the same parent object

UITEXTVIEW is subclass of UISCROLLVIEW which is a sublcass of UIVIEW
UITEXTFIELD is subclass of UICONTROL which is also a subclass of UIVIEW

wouldn’t it be possible to subclass UITEXTFIELD and alter the FRAME or BOUNDS ?

[quote=154431:@Dave S]Remember, UITextField and UITextArea (which are probably the underlying controls used by XOJO) have DIFFERENT supers to start with… they are not derived directly from the same parent object

UITEXTVIEW is subclass of UISCROLLVIEW which is a sublcass of UIVIEW
UITEXTFIELD is subclass of UICONTROL which is also a subclass of UIVIEW[/quote]

Yet it works perfectly. I do not know how Xojo is managed internally, but this trick allows overcoming the height limit for other controls as well.

You mean declare ?

Well in Swift I subclassed them…
and added these new “attributes”

  var left:Double {
        set {
            self.frame.origin.x=CGFloat(newValue)
            self.setNeedsLayout()
        }
        get { return Double(self.frame.origin.x) }
    }

    var top:Double {
        set {
            self.frame.origin.y=CGFloat(newValue)
            self.setNeedsLayout()
        }
        get { return Double(self.frame.origin.y) }
    }

    var width:Double {
        set {
            self.frame.size.width=CGFloat(newValue)
            self.setNeedsLayout()
        }
        get { return Double(self.frame.size.width) }
    }

    var height:Double {
        set {
            self.frame.size.height=CGFloat(newValue)
            self.setNeedsLayout()
        }
        get { return Double(self.frame.size.height) }
    }

remember also, even iOS sets limits on SOME controls (UISwitch for example, no matter what you do the height and width is fixed, same with progress bars, sliders and a few others)

[quote=154423:@Michel Bujardet]@Christoph De Vocht Because I cannot force it be one line only. :slight_smile:
What about managing that in TextChanged ? Seems pretty straightforward …[/quote]

This is not that simple because there is no way you can now how many characters can be displayed on one line. So there is no way you can stop input when the line is full (read: just before it goes to the next line).
I tried several things but no luck.

[quote=154429:@Michel Bujardet]Thank you Dave. This gave me the hint for the workaround. Even if the 31 pix limit should be reported as a bug, I think.

Drag a textarea to the view. Make it any size needed
In the Inspector, change the super to iOSTextField
Voilà ! Height can be managed by changing the Auto Layout height constraint.[/quote]

Clearly a bug. Is there a feedback case for this?

Thank you Dave and Michel for this.

Uh… try this… it LOOKS like it works…

  1. Drag a TextField to the screen
  2. Change the Super to TextView
  3. Drag to the new height you want (you can’t seem to edit it in the AutoLayout are)
  4. Set the Super BACK to TextField (it KEEPS the new HEIGHT)
  5. Set the font size to what ever you want (I used 100 in my test and it works)

Although this ‘trick’ does work it renders AutoLayout useless. Just try to refer to the TextField - it goes bananas. :slight_smile:

imo this is a bug in Xojo that needs to be fixed to make it work properly. :slight_smile:

I tried… :slight_smile: (my opinion AL is useless to begin with…in most cases I would think that if you are supporting one device (iPad for example)… your layout would be somewhat static. If you support from iPhone4s to Ipad then you would most likely have totally different layouts depending on the device (example, a calculator app might have tons of special “keys”, all of which fit nicely on an iPad, but would be too small on an iPhone4s… so you either end up making multiple views, or what I did was base the layout on the real-estate … (yes it took some programming effort, but the results were excellent)… This allowed “shift” key ability to switch part of the keys on the 4s while showing all of the keys on the other devices. My Opinion, you all have yours, and I will respect them if you respect mine :slight_smile:

I also noticed you cannot change the font size ‘in-code’. :confused:

I need this because I would like to alter the font size so the TextField is always showing the text in the biggest possible font size.
So when the users types in some text, the Font size changes to keep everything visible.

[quote=154436:@Christoph De Vocht]This is not that simple because there is no way you can now how many characters can be displayed on one line. So there is no way you can stop input when the line is full (read: just before it goes to the next line).
I tried several things but no luck.[/quote]

Christophe, I am disappointed in you :wink: What happened to graphics text measurement ? Try this :

[code]Sub TextChange()
static oldtext as text = me.text

dim btmp as new iOSBitmap(me.height, me.Width, 1.0, False)

btmp.Graphics.TextFont = me.TextFont

if btmp.Graphics.TextLineSize(me.text).width > 280 then
me.text = oldtext+"…"
return
else
oldtext = me.text
end if
End Sub
[/code]

It makes the TextArea stop entry whenever the width of the text goes over 280, and even adds the elipse.

[quote=154447:@Christoph De Vocht]I also noticed you cannot change the font size ‘in-code’. :confused:

I need this because I would like to alter the font size so the TextField is always showing the text in the biggest possible font size.
So when the users types in some text, the Font size changes to keep everything visible.[/quote]

Change TextFont. That is where you set both the font and it’s size.

http://xojo.helpdocsonline.com/iosfont