Ahoy there,
I’ve been trying to get a button to change it’s background image when clicked/tapped. I thought I had set up everything correctly, but I don’t see the background image changing, despite the button’s state changing. I was wondering if anyone else had come across this, or had suggestions for what might work?
Here’s the button initialisation:
[code] btn = new iOSButton
btn.NormalBackgroundImage = Load.loadiOSImage(“button-cancel-normal.png”)
btn.SelectedBackgroundImage = Load.loadiOSImage(“button-cancel-highlighted.png”)
btn.HighlightedBackgroundImage = Load.loadiOSImage(“button-cancel-highlighted.png”)
btn.DisabledBackgroundImage = Load.loadiOSImage(“button-cancel-highlighted.png”)
ab = btn.AppleButton
ab.AdjustsImageWhenHighlighted = True
ab.AdjustsImageWhenDisabled = True
ab.Enabled = True
ab.Highlighted = False
ab.Selected = False
dlog("init cmdrp3 state: " + enumToText(ab.State), CurrentMethodName)
btn.Name = “cmdRP3”
self.AddControl(btn)
l = l + 67
t = 33
w = 66
h = 56
UI.setControlPos(btn, self, view, l, t, w, h)
AddHandler btn.Action, AddressOf clickedFourth[/code]
(Included the “selected” image for UIControlStateHighlighted, UIControlStateSelected, UIControlStateDisabled for testing, ideally, only Selected/Highlighted will be used).
And here’s the button action event:
[code]
dim ab as AppleButton = sender.AppleButton
If Not on Then
on = True
dlog(“on”, CurrentMethodName)
ab.Enabled = True
ab.Highlighted = True
Else
on = false
dlog(“off”, CurrentMethodName)
ab.Enabled = True
ab.Highlighted = False
End If
//sender.Invalidate
Dlog("cur state: " + enumToText(sender.AppleButton.State), CurrentMethodName)[/code]
In the action event, I’ve tried setting AppleButton.Selected / AppleButton.Highlighted / AppleButton.Enabled on and off to see what changes it makes to the button.
Only disabling (ab.Enabled = False) the control changes the background image, which isn’t ideal, as in the disabled state the control can no longer be actioned. However, the log confirms that AppleButton.State is changing, in this case 0 (UIControlStateNormal) and 1 (UIControlStateHighlighted), which looks to be as intended, just no image change. :’(
Does anyone have any ideas for what might get this working as desired?