create custom segmentControl - ios

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.

Related

Accessibility Label for radio button on action?

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"

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

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

UISegmentControl Customisation

I want to customise UISegmentControl according to link of the screenshot(Shows is selected and News is unselected) given below:
UISegmentControl Customisation
Segment with Title and Image
Borderless segments
Tap event even if Segment(Shows) is selected - I want to perform some action if user tap on selected segment
[SegmentedControlName setImage:[UIImage imageNamed:#"path"] forSegmentAtIndex:0];
For selected event you can use same thing when it also on the touched state.
Only you need to change is the path of the image
I ended up using the following library. It fulfilled my all the requirements.
PPiFlatSegmentedControl

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.

Deleselect uisegmentedcontrol selection after clicking on a save button

I'm using a 3 button UISegmented control for a choice selection. I also have a save button that retrieves the chosen control.
When the save button is clicked I want to have to UISegmentedcontrol cleared (ie the previous selected button unselected). I'm not looking for the setMomentary as I want the selection to stick but also be able to unselect it later.
[myUISegmentedControl setSelectedSegmentIndex:UISegmentedControlNoSegment];
myUISegmentedControl.selectedSegmentIndex = -1; //turn off the current selection
With Swift 4 and iOS 11, the Apple documentation states for selectedSegmentIndex:
The default value is UISegmentedControlNoSegment (no segment selected) until the user touches a segment. Set this property to -1 to turn off the current selection.
Therefore you can use one of the two following implementations in order to remove the selection of your UISegmentedControl instance:
mySegmentedControl.selectedSegmentIndex = -1
mySegmentedControl.selectedSegmentIndex = UISegmentedControlNoSegment

Resources