iOSButton.Enabled = false gives unexpected behavior

Programmatically I enable and disabled iOSButtons. When I call iOSButton.Enabled = false the button is indeed disabled, but the color does not change to the normal “greyed out” color. Disabling the iOSButton in the IDE does “grey out” the button.

Bug?

XOJO 2015R4, Mac. iOS 32 bit target.

probably because the iOS version of Button doesn’t expose the .Highlighted and .Disabled state properties and the associated text and color values

UIButton can have different text, backgrounds, shadows, basically entirely different visual aspects based on the state of the button

I’d still expect the button to change color though, right. In the IDE the color changes when we change the “Enabled” value to false, it just doesn’t do this when we programmatically change the “Enabled” value to false.
I don’t need to access any of the other properties to be honest. I just want it to visually appear disabled when disabled.

I’d file a Feedback case, noting the difference in IDE and runtime behavior.

Seems to work in the IDE, but not in a live app (at least not in the simulator)

The simulator & device are THE standard to compare the IDE to.
If it doesn’t disable in the sim or on an actual device thats “correct”.
That the IDE draws it disabled is the IDE not mimicking the actual iOS behaviour correctly.

When you design a layout for the desktop we get the OS to draw the controls - so they appear correct as it IS the OS drawing them.
For the Web & iOS we cant do that - so we have code in the IDE that mimics the appearance.
And its pretty darned close - but there may be differences - and differences are 99.9% assured to be we’re mimicking things incorrectly.

In short the bug here would be the IDE showing it in grey as “disabled” since that is not correct.

Huh? I think the IDE is “correct” and the compiled code is NOT “correct”

even if you don’t expose the all the attributes of a UIBUTTON, standard behaviour is disabled controls are indicated to the user as being disabled, which is clearly NOT the case here…

But… that’s not how…

Did you even read Norman’s post?

Also, for consideration: http://stackoverflow.com/questions/5715092/disabled-uibutton-not-faded-or-grey
UIButton doesn’t have a disabled look.

Create a simple Xcode project
put in the view 2 buttons
set the “action” for the first button so that enable and disable the other button (i.e.: _btn.enabled=!_btn.enabled)

Run the project
Click on the button the second will become gray (disabled)
Click again the button will return standard.

That’s to say that on iOS disabled button are gray (if don’t set any feature so that it change to another color)

Norman is right: the IDE is just a representation of what needs to happen, but in this case the IDE is correct.

There is a UIControlState 'UIControlStateDisabled ’ for a UIButton.
Perhaps XOJO is missing [button setTitleColor:[UIColor whiteColor] forState:UIControlStateDisabled]; when disabling a button programmatically?

[quote=245552:@Tim Parnell]But… that’s not how…

Did you even read Norman’s post?

Also, for consideration: http://stackoverflow.com/questions/5715092/disabled-uibutton-not-faded-or-grey
UIButton doesn’t have a disabled look.[/quote]
Of course I read his response… and my opinion is the operation is WRONG… a disabled control should be grayed out.
And that Stackover flow has not bearing on the subject. A UIButton CAN be disabled, and the visual attribute CAN be gray (or any other color for that matter)… I do it all the time (just not in XOJO… but then the Stackover flow was not referring to XOJO either)

Here is how SWIFT does it… and all this proves is that the attributes ARE there and they DO work…
this would have BLACK text at idle, BLUE text when selected and GRAY text when disabled… not rocket science
and I left out the examples of adding borders, shadows, background colors etc… Basically an iOS UIButton can have all (more) attributes than an XOJO DESKTOP button can have.

let temp : UIButton = UIButton(type: .System)
		temp.titleLabel?.font=UIFont.systemFontOfSize(17)
		temp.setTitle("Button",forState: .Normal)
        temp.setTitleColor(UIColor.blackColor(),forState: .Normal)
        //
		temp.setTitle("Pressed",forState: .Highlighted)
		temp.setTitleColor(UIColor.blueColor(),forState: .Highlighted)
        //
		temp.setTitle("Disabled",forState: .Disabled)
		temp.setTitleColor(UIColor.lightGrayColor(),forState: .Disabled)

Leave all that out
Just set the control disabled
And ???

iOS itself does not automatically change color when disabling a button.

If you want to do what Dave mentioned above right now and change it, you can look at the included UIButtonDeclares example that comes with Xojo- and copy the UIButton class to your own project if you want to use it there.

you mean like this?

 override func viewDidLoad() {
        super.viewDidLoad()
        let temp : UIButton = UIButton(type: .System)
        temp.frame=CGRectMake(100,100,100,50)  // set button position (non AL method)
        temp.titleLabel?.font=UIFont.systemFontOfSize(17) // equivalent of XOJO Font property in Inspector
        temp.setTitle("Button",forState: .Normal) // equivalent of XOJO Caption property
//
        temp.enabled=false // equivalent of XOJO enabled property
//
        self.view.addSubview(temp)
    }

Leaving everything but the font size and label as default…

If enabled is FALSE, the text is “iOS Blue”, if true it is “LightGray”… exactly what XOJO is not doing on the device, just in Sim

[quote=245586:@Travis Hill]iOS itself does not automatically change color when disabling a button.

If you want to do what Dave mentioned above right now and change it, you can look at the included UIButtonDeclares example that comes with Xojo- and copy the UIButton class to your own project if you want to use it there.[/quote]

That is my point… because it DOES…

That’s getting into the distinction between what either language support framework does and what iOS itself does. That doesn’t help David change the color on his buttons in Xojo either way.

The bottom line is if anyone else reading this wants the color changing behavior described today in Xojo, they can just copy the UIButton class from the included UIButtonDeclares example and be on their way. Whether or not the Xojo framework should default to that behavior on top of iOS is certainly worthy of consideration too (I actually don’t disagree myself)- I’m just trying to help David get the result he wanted from Xojo right now.

Sorry… partial confusion as to which DAVE you were referring to :slight_smile:

I’m still unsure as to what is ‘expected’ behavior, but I’ll beat a hasty retreat.

As I’m changing the state programmatically, I simply set the color programmatically at the same time.

Disabled:

iOSButton.TextColor = &cBBBBBB

Enabled:

 iOSButton.TextColor = &c007AFF

seem to work well.