I'm currently developing a Body Mass Index calculator for the iPhone using segmented control to switch between the various weight and height units, at the moment I have a text field in which the user inputs the values.
My question is this; is there a way to change the text field to two separate text fields?
For example if the user selects "stone & lbs" from the segmented control the single text field will be replaced by two text fields for input in stones and lbs.
Any help will be greatly appreciated!
You have a view Controller. The job of that controller is to control views.
So, as an indicator, Have your view controller create and display one text field when for a unit selection that takes one value, and that creates, and displays two text fields when using something that needs two text fields.
The controller can also take care of hiding the fields that aren't being used, and you can even use UIView animation to attractively animate the changes from single to double text views.
Related
UPDATE: I am adding a photo that may better demonstrate the type of thing I am trying to achieve.
I am creating an app where a user can set as many filters they like on a stream of images. I would like to display each filter they have set as a button with an X in it if they would like to remove it. I have created my own buttons and assigned actions to them, but this would be my first dynamic button project.
My confusion how to programmatically create the button, assign it an action that knows which filter to act on, and then arrange it so that the buttons behave like text in a text box such that if a button can't fit on the screen it "word wraps" to the next line.
I have a an array of the filters they have applied that I can loop through, I just don't know what the mechanism is for arranging them so that each button acts like its own word in a sentence. As a work around I could use a table/collection view but since the width of the filters varies amongst the potential buttons I was really hoping to not force a uniform width as those would require. I have seen apps that do this so I am hoping the experts on here can help.
I suspect the solution looks something like:
For loop that has for each filter in Filters
Create and configure a UIButton with the text title of the filter
Assign an action that takes an argument so I know which filter to remove
Assign constraints appropriately so it fills the width of the screen but "word wraps" once it can't fit and whatever container object it is in increases in height which would need to adjust in landscape mode
// Can a #selector take an argument like the filter's array location?
myButton.addTarget(self,action: #selector(helloButton), forControlEvents: .TouchUpInside )
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.
I have made an InfoPath form with several views. A user can only go to the next view when all needed fields are filled. Therefore, the next button is disabled. To inform the user, there is a calculated field dispalying "please fill out all needed fields to go to next view". When all fields on the view are filled, the calculated field is hidden and the button is enabled. When the field disappears the button is moving one Level higher to the direction where the label was. Is there a way to lock the button on the view?
If you look carefully you can see that the button (and the Label "1/6" is moving up)
Best regards,
Julian
Here is a trick: try changing the font color to the same color as background. It is like hiding the message by changing the font color so it won't be visible.
You might want to put the different objects inside a layout table, and then set specific heights for the layout table rows. Then when something is hidden, like the calculated field, the other objects stay where you'd like them to be.
I am building an iPhone app for a library and I want to give few options to the user to search books by. A user can search a book by title, author, topics, or date of publication.
What I want to know what's the best way to display these search options to the user? In terms of HTML, it would be easy - either use a drop down list or radio buttons. I tried using UIPickerView but honestly, that looks terribly ugly and destroys the aesthetics of the view of my app.
The other option I was thnking was using segmented control, but is it possible to have a vertical segment control in stead of horizontal one? The selection texts can be too long.
Any ideas?
If you want a vertical segmented control, you'll have to make it yourself. Create a textured image with dividers. I would export each section as a PNG separately. Then create a picture of each section with the "pressed down" gradient and export each segment as a separate PNG again.
I would then make a new class. If there is a specific number of objects in your segmented control or this is a one time thing, the class may not even be necessary. If not, then in the class constructor pass an array with the titles of the segments in your segmented control. For the first and last objects, use the pictures you made with rounded corners. For the objects in between, use the standard pictures. Then put the titles on top. When a segment is tapped (perhaps use hidden UIButtons), you can use a delegate method to tell the main search class which one was tapped, and then the class can replace the normal picture of that segment with the pressed down one.
Thanks for the options.
I ended up creating a simple table to show my choices.
User clicks on "search by", which opens up the table with options and then when you select any option, you return back to main view with the chosen search option.
I am showing a form the user fills in my iPhone app. One of the fields is a set of 2 or 3 dates from which the user has to pick one. Putting a picker, or bringing up a table view just for this takes up too much space, leaving no room for the other fields. Is there any simpler way to do this?
To do this you can put two or three arrowed label with text like "Select Date" upon click of it you can show one view that allow user to select the date; once selected you can back to the original view. You can do this for all three (or two) dates and get those date on form view.
I am giving you idea of how you can design apps; if you want code i can assist that too but from your question it seems you want design ideas.
You can go for your custom drop down/combo box, but their is no inbuilt functionality present for this.
Also following is mentioned in apple HIG guideline, you need to consider those as well-
(http://developer.apple.com/library/IOs/#documentation/UserExperience/Conceptual/MobileHIG/UIElementGuidelines/UIElementGuidelines.html)
Guidelines
Use a picker to make it easy for people to choose from a set of values. It’s often best to use a picker when people are familiar with the entire set of values. This is because many, if not most, of the values are hidden when the wheel is stationary. If you need to provide a large set of choices that aren’t well known to your users, a picker might not be the appropriate control.
Consider using a table view, instead of a picker, if you need to display a very large number of values. This is because the greater height of a table view makes scrolling faster.
Use the translucent selection bar to display contextual information, such as a unit of measurement. Do not display such labels above the picker or on the wheel itself.
On iPad, present a picker only within a popover. A picker is not suitable for the main screen.