How can I create this Switch behavior? - ios

I want to create the following selection button to pick from the two options "Salary" and "Hourly Wage".
I have images for when either (left or right) option are selected.
What UI element in iOS can I use to create this? Looked into a Switch but did not see an option on how to set custom backgrounds.
Obv in code I will need to know which option is selected also. Should I be treating these as two separate UIButtons right next to each other?

The control you are looking for is a UISegmentedControl - see the Apple Docs.

Related

Is there a specific component that works with Swift 3 to represent a "ComboBox / Spinner"?

I'm starting to work with Swift 3 and I'm having difficult to find a "easy" solution to create a "ComboBox/Spinner".
I saw some alternatives like using PickerView and Collapse TableView, but It seems to be a solutions to make these components to looks like a ComboBox, It's a adaptation, but It's not a "real comboBox".
I would like to know If there's a component that works with Swift 3 that really represents a ComboBox/Spinner.
Thank you.
As Eric says in his comment, controls aren't defined in Swift, they're defined in the OS frameworks.
iOS does not have a combo box. That's a Windows thing. The standard system component for picking items from a list is a UIPickerView. I've implemented a custom control that's rather like a combox box before, and you may be able to find a 3rd party control that does what you want.
Don't know if this is the kind of combobox system you are looking for:
https://gyazo.com/ce6388cf29f9c33f67df2b6a54c95768
If so you could create a custom button which looks like a combobox. Then if not selected you have an image of a not selected combobox and when someone selects the button change it to the image of a selected combobox.
You create an array, add the amount of custom buttons to the array as you want, you give each button the same selector. Then when someone selects an item, deselect another button if there is one selected and select the button the user did press.
I hope this helps you.

How to make radio button with swift?

I am trying a lot of code and it's nothing is working for me. I need to make four radio buttons with swift when I show the question for the user to choose one of radio buttons.
Sadly, there's not a built in way to do this with Swift, but it's easy enough to code out. I'd personally recommend using this Git project, as I've heard good things about it.
If you'd like to built a radio button from scratch, I'd suggest looking a making a check button by using a regular button with a UIControlStateSelected triggering a check img, and then set the layer.cornerRadius (after setting the clipsToBounds = true of course) of your button to half its width to produce a circle!
You can create your own login by using a mutabledictionary with button tag as key for dictionary. Add green/selected image for selcted button & set "yes" value for key (button tag) in dictionary for selected button & "no" value for other button's tag.
I have an example for the same but in Objective -C
The UIControl that offers the closest behavior from radio button in swift iOS is the UISegmentedControl, take a look at the reference.
Here's apple's guidelines for mobile controls.
Some quotes from this article :
Use a segmented control to offer choices that are closely related but mutually exclusive.
A segmented control:
Consists of two or more segments whose widths are proportional, based on the total number of segments
Can display text or images

options control in ios (Swift)

I would like to show options to choose in my View. I did not found a control for that. Any suggestion howto do that ?
You must use 3 different buttons for the check box,now set different tag for the buttons and set default and selected image for the button.

Xcode buttons/images always on top?

Is there an option for a button/image to set, that it will always be shown on top? So I have 2 buttons and want to add an image. But the image covers the two buttons and I have no idea how I could get the image in the background or the buttons in the front.
BTW: I´m fairly new to xcode and programming...
Use the xCode top menu item Editor->Arrange. There you have options to handle z index for controls.
What I did was, to have two button one for the label and one for the image and when one is clicked it propagates the message to the other and does the action depending on which one was clicked.

In Xcode Interface Builder - why are the options in the Editor--->Arrange menu (containing Send to Front, Send to Back) often disabled?

What I'm trying to do is simple: bring a label in front of an image within a subview.
But all of the options for arranging are disabled/un-selectable when my label is selected. I find this happens often.
What could be the reason that I'm almost never allowed to change the z-axis of my objects in the Arrange menu? Is it a better practice to avoid this feature and set the order of views programmatically?
It can depend on how you have selected the label (similar to how the label can only be moved with the keyboard when selected in some ways).
A simple alternative is to look at the list of view in the pane on the left and to drag the views up and down to change the order.
It happens sometimes. In that situation, click the view or image you want to send back then you will see little square box at the edges of image from which you can re size your image, Just click on it once and then go to Editor > Arrange > Choose option according your need.

Resources