Assign backdrop to iOSTextField

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:

[code]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
[/code]

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

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 :slight_smile: )

Thank you Jason :slight_smile:

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

[code]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
[/code]

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?

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.

You’re right.

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.