Accessibility Label for radio button on action? - ios

In TableViewCell, I have custom imageview which act as a radio button. This imageview has two states
Selected
Not Selected
By default I have given, Accessibility label as "Selected Checkbox" and "checkbox". Now I want to speak voice text as "new item selected" when it selects and "item deselected" when deselected.
Can we give all four different label? How can I get the same.
Updated: I tried using
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification,#"text")
but it skips the text which need to speak.

I'm not entirely sure what you are attempting to do here but I'll try to provide an alternative way of making this accessible.
Instead of treating each radio button as either selected or deselected would it not be better to treat the entire group of radio buttons as one combined accessibility element.
So if you have radio buttons for [cat, dog, rabbit, guinea pig]. Then your accessibility should read something like...
Animal selection group: none selected
or
Animal selection group: rabbit selected
etc...
Having said all of that... what is this UI you are trying to create?
Radio buttons are fundamentally not a part of iOS. It would be a much better alternative to use UI that users know. And then by doing this you make your accessibility issue a non-issue.
Perhaps a UIPickerView or a UITableView might be better alternatives to radio buttons?

Not sure what are you exactly want to do.
My assumption: You want to generate sound on click of a button for tableviewcell and also changing the image of Imageview at the same time while checking the state of it (selected or non-selected).
***** do it inside your customTableViewCell class...
create IBOutlets in .h or .m for your 3 items from customtableviewcell xib.
create boolean flag to maintain current state (selected or non selected) of that cell.
create IBaction selector(method) to get event(touch up inside) of button click. Inside this method write code which checks following.
BOOL selectState; //Make this Global in classfile
if(selectState) // selected state YES
{
xyzImgView.image = //Your Non selection Image;
selectState = !selectState;
//Play your sound for Non selection
}
else // selected state NO
{
xyzImgView.image = //Your selection Image;
selectState = !selectState;
//Play your sound for selection
}

// Considering you have an IBOutlet to checkBoxButton
checkBoxButton.accessibilityLabel = checkBoxButton.isSelected ? "selected" : "not selected"
checkBoxButton.accessibilityHint = checkBoxButton.isSelected ? "" : "Tap to select"

Related

How do I force a button response to say a text vs its label?

Scenario: User has 5 stars (buttons). Each button has a UIAccessibility label to describe the star ("First Star of Five", etc.).
Problem: Upon selection, UIAccessibility repeats the label. I want to change that to 'Selected' (or "You have selected the 2nd Star.").
Attempted Solution:
I tried to squash the button's action response and got silence; which is expected, I guess.
cell.button2.accessibilityLabel = #"Second star of Five.";
cell.button2.accessibilityTraits += UIAccessibilityTraitStartsMediaSession;
But I also don't want an automated repeat of the label.
How can I have full control of 'Voice Over' upon selection of each star button so user understands the selection vs merely repeating the label?
Per suggestion below, I can't override the accessibilityLabel of my custom button class. I have ObjC code, but prefer to work with Swift. So I'm trying to incorporate the custom UIButton class written in Swift, into ObjC.
Define a CustomStarButton and overwrite the - (NSString *)accessibilityLabel{} func, if selected, return #"You have selected the 2nd Star."

Make a button appear selected

Is there a simple way of making a button appear selected with Swift? I currently have a series of buttons with background images. I want each of the buttons to appear 'selected' once tapped by the user; each button will be used to specify which options the user requires.
When you select your button you could change it's state to selected:
func buttonTapped(button: UIButton) {
button.selected = !button.selected
...
}
And if you want, you could change the background image of your UIButton to have a different image when it's state is selected like this:
button.setBackgroundImage(selectedImage, forState: .Selected)
This can also be done in Interface Builder:
You can make a button appear selected several ways. One is to have a second image which is slightly darker (i.e. looks depressed) and when you set the button's state to button.selected = true then the system will automatically use this second image for it's selected state. If you don't have a separate asset (which I wold recommend you do) then you can set button.userInteractionEnabled = false which will make it unable to be acted on by the user, as well as change it's alpha component or color or some other property to enforce to the user that the button is no longer selectable.

create custom segmentControl

I'm trying to create a rather custom segmentControl. What is the easiest way to create such below. with just text and a border line the selected?
You can create buttons and give tag to each of them,which will identify which button has been selected.Whenever a button is marked as selected change the state to .selected with its image.
Choice -1
ya just created 4 buttons and create the one common method , inside the method assign the tag for each button for identify which button is selected , on that selected button change the TextColor and use use Underline,else button are another color
Choice -2
ya just created 4 buttons and create the one common method , inside the method assign the tag for each button for identify which button is selected , on that selected button change the Image in UIControlStateNormal else no selection Button use normal Text or another Image
You can make fastens and offer tag to each of them,which will recognize which catch has been selected. Whenever a catch is set apart as chosen change the state to .selected with its image.

How to set focus from one UIButton to Another UIButton in UIToolbar Done Button

I am working with iPhone Application with creating single object multiple dynamic button in UITableView. And when user will press button every time UIDatePicker will open to select date. So Is is possible to move focus from one UIButton to another UIButton after date selection. I am explaining you in detail as follows:
I have create UITableView with single object Multiple Custom UIButtons. When user will click on all this button the UIDatePicker will show with Next and Cancel UIToolBar. When user select date from datePicker and press Next button i want focus or select for the next UIButton to give facility to select date from datePicker for another button. Like flow without removing view for transaction.
So is it possible to Focus on another button after pressing Next button to another button.I googled around but could not find any solution for this.
Please help me for this.
Yes You can.. Perform following steps:
Set Different style for your buttons for Highlighted state.
Give a unique tag for each Button.
Lets say you have 5 buttons with tags 0 to 4. In your TouchUpInsideEvent write this,
(IBAction)onButtonClick:(UIButton *)sender
{
for(UIButton * btn in myButtons)//Mybuttons is outletCollection of buttons
{
if (btn.tag == sender.tag + 1)
{
[btn setHighlighted:YES];
break;
}
}
}
If it does not work with Highlighted state, you can try with Selected state. (I think it will work with selected state only .. :))

How to select a UITextField without showing UIKeyboard

I am wondering if there is a way to use a UITextField programatically (i.e. use buttons as inputs) so that you can select a UITextField but not show the UIKeyboard, then when you select a UIButton it would assign a string value to the currently selected UITextField.
I don't really know where to start.
I think you can visually change the appearance of the text field (for example add a blue border), let the user feel it’s “selected”. Then you just modify textfield.text when user presses button.
Or alternately, you can create a customized keyboard. There are many similar questions.
It seems that you don't really need a text field (e.g., edit/select text, etc.), but a "button that stays highlighted" instead. Then, you can programmatically change the button's title label to the specified string when the user taps the 'proper' buttons.

Resources