UIButton Image Not Changing With Interface Builder Settings (Selected & Disabled) - ios

I am trying to set the toggle state of a UIButton through the interface builder. I have done it successfully using code, but I need to get it working through the interface builder.
Im not sure what the issue is but for selected I set its image to 'flashOn' and for disabled I set it to 'flashOff'
When I hold down the image, it shows the 2nd image, but pressing the image does not toggle between these two images.
Im certain it's super simple so if you can suggest what I am missing I would appreciate it

A button's selected and disabled states need to be set in code.

Can you show your implementation for when you got desired results through code? I think, from what I can piece together from your question, that you have mixed up the states of the button.
Default - images will display for this button in any state unless another is specified explicitely
Disabled - image will display when button is disabled. (button will not switch from this state through user interaction as it is disabled)
Selected - image will display when the button is selected, which as far as I know is only when you set the button as selected through code.
Highlighted - image will display when you press and hold down on the button

Related

iOS: UIAccessibility (Voice Over) with checkbox is not working properly

I am using voice over on checkbox.

The issue I am facing here is,
when user selects the checkbox for the first time it says 'checkbox selected' (which is correct as per accessibilityLabel set) but next time when user tries to de-select it says 'checkbox selected, checkbox de-selected' where it should only say 'checkbox de-selected', vice-a-versa.

So what is happening here is that, the previously set accessibilityLabel is not getting cleared up and when user tries to select or de-select it takes the both previous and currently set label.

Note- using custom checkbox, toggling UIButton with selected/de-selected image.
How to solve this conflict? 
If you create your checkbox thanks to a UIButton item, I suggest to :
Untick the button UIAccessibilityTraits.
Provide a clear hint when the checkbox is first selected : "double tap to change the value".
Update your button accessibility label thanks to IBAction when the box is toggled.
However, it's always better to create a UIAccessibilityElement that contains your check box and a label that describes what it refers to ⟹ when you double tap this accessible wrapper with one finger, the checkbox value toggles and your initial problem disappears.
Following these steps will provide an appropriate user experience with no checkbox VoiceOver conflict that you noticed.

Handling Button states

Hello I have another problem/question. I have a custom control with a button on it:
I want to delete an image from it, so I removed the reference from Attributes inspector -> Image, so now my button in designer looks like this:
But when I launch it on simulator, when I press the button (just push it, not making a click ) the image shows up! Where does it come from? Are there any button states styles in project files, where this could be written?
Because button has two references - 1 outlet and 1 action and none of those are used to add image to the button! I just don't understand where from the image gets in...
You should remove the image for both normal and selected states of the button from the attribute inspector(check stateConfig attribute).

Detect second click on a segment

According to the documentation, the event which should related to UISegmentedControl is value changed. Assuming I have a segmented control with previous and next, in my case I should be able to click next more than one time, the default behaviour of UISegmentedControl will not recognize the successif second click on same segment. SO how to deal with that?
Set the momentary property of your UISegmentedControl to TRUE.
You can do that in code or in Interface Builder (there is a checkbox in the Attributes Inspector).

How do you set the selected image for a button in Xcode?

I know how to change the image programatically when a button is pressed, but there must be a way to do this non programatically in Xcode, but despite searching high and low I simply cannot see anywhere in Xcode where the selected image can be specified.
Try in your storyboard. The second selection (STATE CONFIG) down in attributes inspector should show "default" for your button. Change the sate (Highlighted, selected, disabled) and then change the image in the image box 8 down or background image underneath.
Open up the "Attributes Inspector" in your storyboard or XIB and the image name is an attribute you can set in your UIButton object.
Also make certain to make the "Title" empty or a string will be drawn over your image.

Displaying at different times

I have a split view app that displays a thumbnail image and a button for continuing to the full view. The label, right now, is just there to make sure that the button works because I have yet to connect the full view. When the app first opens, the image is not displayed since the user has not selected an image at that point, but the button (and label) are displayed anyway. How can I get the button and label to be displayed only once a user has selected which image to view from the table?
Change default settings in Interface Builder for the button to start out as hidden, and also make sure that it starts out disabled so that users don't accidentally click it without knowing that its there, then add the following code to where you detect whether or not the image has been selected.
yourButton.enabled = YES;
yourButton.hidden = NO;
Let me know how that works out for you!
-Karoly

Resources