I want as an option in an app I'm building to offer the user to select between seeing temperatures in Celsius (C) or Fahrenheit (F). This option will be shown within a tableview controller.
My initial thought was to use an UISwitch for this but this would require adding labels left and right of the UISwitch and linking the on/off to either C or F.
Is there a better way or will I need a custom control for this?
Thanks!
Kostas
I would use UISegmentedControl for that:
It would look like that:
As you see you can make multiple items so if there is another option to choose, you can easily add it.
Related
I am a very basic SWIFT Xcode programmer. I make small apps.
For last 2 days, I am stuck at a very simple thing and I am sure with your guidance I can quickly make a decision.
I have a UIViewController class as well as an xib
In the layout I have 4 textfields
Now based on a user setting (in another frame user make a choice), I will either have to show 4 textfields ** OR ** 3 textfields and a UISwitch.
Long story short, if user select one option he should see UISwitch and 3 textfields or else 4 textfield. The labels's text also change.
To my limited knowledge, I will make another UIViewController, another XIB file and if user selection allows I will segue to the new UIViewController.
But all this looks so redundant. How do you smart people do this thing?
(Edit)
I use size classes in my layout as well as constraints in the visual editor for positioning of elements on the layout. If I change things programmatically, which is one option, how will I manage the layout ?
Please advise.
Show me the right path please.
When user select first option based on action show or hide the text field or switches, like when user select first option only show three text field and one UIswitch hide fourth text field.
And programatically change text field hint value and also set NSString Tag="first" so that when you want that value at the time of submit button you can apply if condition to tag and on that basis you can get your desired output on each selection.
currently I'm using the SVSegmentedControl by Sam Vermette - works great, but I'm asking myself if it's possible to change the layout of the SVSegmentedControl or the UISegmentedControl in general?
I want to have 2 rows with 2 "cells" / row, is that somehow possible?
Thanks
If you want to have 2 rows, each with two cells, this isn't a thing that you can change with default segmented control behavior.
If you want something that looks like a box with 4 sections and behaves like a segmented control (only allows one part to be selected) then create 2 segmented controls. Customize how "it"(they) look(s) with backgroundImageForState:barMetrics: and other similar methods. When you detect that one of the control's parts has been selected, then deselect all of the other parts in both controls.
If you look at the source code, it doesn't actually inherit from UISegmentedControl, instead from UIControl. So if you wan't to customise UISegmentedControl, your best bet looks like building a similarly behaving control from scratch.
I am trying to make an update for my trivia app and want it so that when the user types in the answer he/she only has the option to click A,B,C, or D. Is this possible? and if so, would apple allow this and how do I do it?
You could also just create a custom view with four buttons that appears when necessary. It would be easier than customizing the keyboard, and depending on how you design and implement it, it'll probably look better than an action sheet. UIView provides a rich set of methods to animate views with ease.
Yes, you can customise the keyboard, all the documentation is in the developer library. But it sounds to me you'd be better off using a UIActionSheet if all you are doing is picking from four options.
Edit: For reference, have a look at Custom Views for Data Input in Apple's Text Programming Guide for iOS.
This question already has answers here:
How to create a UITableView with editable components?
(2 answers)
Closed 3 years ago.
I need to present the user with a screen with controls (i.e. a dialog). It will display some labels and different types of controls so that the user can do some configuration:
select a color (custom color picker)
select a line width (slider)
select one value from a list of values (UISegmentedControl?)
enable / disable one option (On/Off)
...
I am evaluating different alternatives:
Create the layout with labels and controls in InterfaceBuilder
Use a UITableView, so that each cell contains a label and its control
I like option 2 because it is similar to iPhone Settings app, and it makes the screen look organized, giving you sections, scroll..., but it is a real pain to create in code all different cell layouts, taking into account each row heights...
The solution has to be easiliy maintainable, allowing easy reuse of code, DRY (low repetition), data-driven...
Is there a recommended or standard aproach to do this?
Instead of implementing it yourself you might also like to consider some of the open source solutions. I use InAppSettingsKit in my app. There are a few minor UI glitches but it works well. I also evaluated mySettings (indeed I submitted a couple of patches) and InAppSettings.
Even if you don't use them, you might be able to crib a few ideas from them.
You can create the tableview cells in IB and then just create IBOutlets to each cell, and then return each cell in the data source method (forgotten the exact name of it, its where you normally create cells)
You could create a cell in IB for each cell or create different types of cells in IB, say one slider based cell, etc and programmatically change the text, etc.
This is staticly creating a tableview, theres an Apple guide on it somewhere.
you said it. use a UITableView and create custom UITableViewCells (probably in Interface Builder!) and add these in.
Also, as far as selecting a value from a list of values.. a drill in UITableView (embed the root UITableView in a navigation controller) with all the options and then a checkmark is probably advisable (this is how most apps handle this behavior). The On/Off button is more suited for UISegmentedControl.
There are great examples of this in this book.
Good luck.
Lets say my UISegmentedControl has 8 numbered segments. I would like for the user to be able to turn on 2, 3, or more of them at once. Toggling them. Essentially like a bits in a byte. Is this possible? I believe it is on regular Mac OS X but I can't seem to find a way to do it in the iPhone SDK.
If I have to simulate this by putting buttons into a view, is there any way to do the following:
Round the corners of the view so that it looks like the "bar" style UISegmentedControl?
Use the built-in backgrounds the "bar" style has on the buttons?
Give the buttons a shadow like the whole "bar" style has? (not the text)
Update: The custom control I mentioned here no longer works under iOS 13.
This is the best custom control I've found that allows multiple segments to be selected concurrently:
https://github.com/yonat/MultiSelectSegmentedControl
This one is a subclass of UISegmentedControl, which is convenient. I've forked it here:
https://github.com/stewartmacdonald/MultiSelectSegmentedControl
and added some code examples to the ReadMe and added a method that allows you to get an NSArray of the titles of all selected segments.
This isn't possible using UIKit. I would recommend creating a custom control, or an array of UISwitch controls, representing each of the options in your UISegmentedControl.
I think the simplest way is to create your own segmentedcontrol with UIButton.
Marco
There appears to be a way to do this in XCode now. In the Attributes Inspector, there is a section with Segment, Title, Image, Behavior. The behavior options are "Enabled" and "Selected". You can selecte "Selected" for multiple segments.
I recommend you try https://github.com/tayhalla/THSegmentedControl
it is an actual subclass of UISegmentedControl so it fits nicely with Interface builder and everything.