Assign backdrop to iOSTextField

  1. 7 weeks ago

    Michel B

    Jul 4 Pre-Release Testers, Xojo Pro RubberViews.com
    Edited 7 weeks ago

    For my latest project, I need to assign a picture to the iOSTextField, as described here:
    https://developer.apple.com/documentation/uikit/uitextfield/1619623-background

    I thought I could modify code to assign backdrop image to an iOSButton, but the UIKit structure is quite different.

    Here is what I have now. It simply freezes the app and never shows the picture:

    Public Sub Backdrop(extends TF as iOSTextField, assigns backdrop as iOSImage)
    
      declare sub setBackgroundImage lib "UIKit" selector "background:" (obj as ptr, value as ptr)
      setBackgroundImage(TF.Handle,backdrop.Handle)
    
    End Sub

    I am not familiar enough with the notation in the doc. I must have left something out.

    var background: UIImage? { get set }

    Has anybody done that before ?

    TIA

  2. Jason K

    Jul 4 Pre-Release Testers

    Try changing the selector to “setBackground:” instead of background. The “set” means setter. Without it you are trying to use the getter. (And for booleans the getter will prepend “is” instead of nothing, nice and confusing :) )

  3. Michel B

    Jul 4 Pre-Release Testers, Xojo Pro RubberViews.com
    Edited 7 weeks ago

    Thank you Jason :)

    Well, now it does not freeze anymore, but the picture never shows.

    Public Sub Backdrop(extends TF as iOSTextField, assigns backdrop as iOSImage)
    
      declare sub setBackgroundImage lib "UIKit" selector "setBackground:" (obj as ptr, value as ptr)
      setBackgroundImage(TF.Handle,backdrop.Handle)  
      
    End Sub
  4. Dave S

    Jul 4 San Diego, California USA
    Edited 7 weeks ago

    from my dealing in SWIFT, the UITextView doesn't support SetBackgroundImage
    but it does support using an Image as the Background COLOR (however it is tiled across the control)

    this would be the "Swift" version

     //BACKGROUND IS TILED=True
            temp.backgroundColor           = UIColor(patternImage:UIImage(named:"image$0003.png")!)

    other controls required using CALayer, or drawing into the graphic Context
    but I think I have managed to find the SWIFT combinations for most of UIKit,.... too bad they are not "consistent"

    What does Xojo do if a declare such as you have above fails?

  5. 6 weeks ago

    Michel B

    Jul 5 Pre-Release Testers, Xojo Pro RubberViews.com
    Edited 6 weeks ago

    Thank you Dave.

    Now I realize I was trying to apply a UITextField attribute.

    Is Xojo's iOSTextField a UITextField or UITextView ? Intuitively, I would say iOSTextArea is a UITextView, and iOSTextField is a UITextField.

    I hope someone who knows chimes in.

  6. Ulrich B

    Jul 5 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    @Michel B Is Xojo's iOSTextField a UITextField or UITextView ? Intuitively, I would say iOSTextArea is a UITextView, and iOSTextField is a UITextField.

    You’re right.

  7. Michel B

    Jul 6 Pre-Release Testers, Xojo Pro RubberViews.com

    OK. I believe my code is correct, but yet, the picture never shows. I also tried disabledBackground to no avail as well. I though the dimensions of the picture explained the failure, but after setting up a picture the exact size of the iOSTextField, no error, but nothing shows up.

    I finally created a custom control with a container control, with the picture underneath the iOSTextField.

or Sign Up to reply!