I want to create a 'hidden custom cell' effect like that used in the popular 'pull to refresh' pattern (http://stackoverflow.com/questions/9076905/uitableview-hide-first-cell). I'm not creating a pull to refresh interface but I want a special cell at the top.
I can work out how to do this using the many pull-to-refresh examples but they all create the hidden view in code. I would like to create this in interface builder.
How can I do this? I would like to use storyboard if at all possible.
the concept is very simple. The idea is to set a negative edge inset for your tableview. SO assume your first cell is 44 px in height:
[self.tableView setContentInset:UIEdgeInsetsMake(-44.0, 0, 0, 0)];
the following code will cause the table to start showing the content 44 pixels down, which will create that hidden cell effect.
You can achieve the same thing with interface builder. It is in the size inspector under 'Scroll View Size'. You will have to set the Content Inset for the 'Top' attribute to a negative number.
hope this helps
Related
I can't change a position and size of title and subtitle label in Interface Builder. What should I do?
You can't edit the position of the default UITableViewCell subviews in interface builder. You can change the text alignment, content insets, and other related properties but you can't explicitly change their frames. You can do this in code when you are displaying the cells themselves as some other answers point out, but I recommend against doing this as it can cause some other side effects when Apple makes changes to these components.
If you need to customize the position of these subviews, you should instead just build them manually. You can do this in interface builder by selecting the cell, then selecting the 4th tab on the right (Attributes Inspector), then change the Style to Custom. Once you do this, the default subviews will disappear in interface builder and you can just add your own.
You have chosen the default cell style for your cell. The Title and Subtitle labels for the chosen style you see are some basic UI controls that are meant to be used for typical scenarios of displaying content in a tableView usually. If the framing of the labels are comfortable and okay to you, then it is fine. If not, you need to make your own custom style cell.
Basically you cannot modify the default cell style that Apple provides. Just make the cell style Custom and do whatever you want with the layout.
My application gathers input from users and hence it is full of Labels, text boxes and buttons and I have to show or hide set of labels and text boxes based on certain conditions.
To accomplish it, I did the following.
Set fixed height (lets say 30) for all the controls
Set height constraint on each of the controls and created an outlet to the height constraint in the ViewController
Alter the heightConstraint.constant value programatically (between 0.0 and 30.0) based on the scenarios.
Having programmed like this, it is very difficult for me if there is any change in layout. (i.e., if user requested to add/remove any particular control from the view Controller).
I am using Auto Layout constraints. Could anyone suggest if there is a better way to accomplish my goal.
I am using IOS9 and Swift.
Many thanks in advance.
You can use UITableViewController with static cells for this case.
For hide/show row or section, you can change the size in the tableView:heightForRowAtIndexPath method.
UITableViewController automatically manages the layout and with static cell you can even create outlet for all the controls.
Have you considered using a table for this? It has mechanisms for inserting and deleting rows and would manage the layouting for you - only part you'd need to care about are the contents of the cells.
Instead of making IBOutlets to the height constraints of all the views that you might need to hide, you can just use the hidden property of UIViews to hide/show the view.
In case you need the view to make space for other views, you could set a simple animation and move the view out of screen bounds. You might face issues with layout constraints but it's surely worth the effort from a UI/UX perspective.
Additionally, if you know that you don't need a view any more you can even remove the view from it's superview.
I have the following issue in my iPhone app.
I have 4 buttons in my IB also linked to my UIViewController (IBOutlet)
When I for example hide the second button which is AfvalSoorten with [self.btnAfvalSoorten setHidden:YES]; then it disappears, that's what I want, but I still got the button space when I debug the app on the simulator.
How can I get rid of that?
Below there is an example.
Is there an option on the Storyboard for the buttons to clip together?
You should use autolayout. Otherwise it's a nightmare with the new screen sizes.
With autolayout you can do what you ask programmatically: setup the buttons with certain constraints and then when you decide to hide the button remove the constraints that are not needed. It's flexible and powerful but not the easiest way for a beginner.
One simple way to do it is with additional constraints. For instance, if you have buttons 1, 2 and 3 (see screenshot), and you plan to remove button 2, you can add an extra constraint between 3 and 1:
That constraint should have less priority (250 in my example) than the others (1000 by default). That mean that the constraint won't be applied when button 2 is in place (with higher priority constraints).
Then, remove the button instead of hiding it.
[self.button removeFromSuperview];
When you hide the button it still considered by the layout system to take decisions, and it makes layout more complex. If you want to keep the button around make sure it's using strong modifier in the property declaration.
A better approach for above scenario - You dont need to set any autolayout or frames :)
Use UITableView and create custom cell with UIButtons in it.
Set UITableViewCellSelectionStyle to None
Here your button background is same for all cell
Create an array with above button titles
When ever you want to hide buttons just remove it from array.
The modern preferred way of doing so is to use Stack Views. Great tutorial. Requires iOS 9.
You'll find the icon of stack view in the Auto Layout toolbar at the bottom right of the storyboard canvas.
You had just make it hidden.
You have to set the frames according to your need.
OR
You can set autolayout.
maybe there is a solution with autoLayout in IB but I'm not sure about that. Programmatically you can add all your button to an array in order. and whenever you hide a button or not you loop trough the array of button and each time you find one that is not hidden you set the y coordinate on the frame to a a value and you increment this value by what you need so the next not hidden will be placed according to the last position used.
You can add the buttons programmatically -> you will have the array
of Btns and method to add array to the view controller.
You can play with the Constraints and set Height Constraint for 2nd button when hide it to 0 but all buttons should be connected with the constraints in this case.
I want to create a footer fixed to the bottom of the viewport in an iOS app I'm developing (it's my first one, I come from a web dev background). However I'm having difficulty finding information on how to go about this.
What I have in mind is essentially just 3 rectangular buttons next to each other that are just constantly fixed to the bottom of the viewport. I tried dragging a toolbar into my scene as a starting point, but in the interface builder it's placing itself under my table cell, rather than fixing to the bottom. I feel like this is probably easier to do programmatically, but I just don't know where to start.
If someone could at the very least guide me in the right direction I'd really appreciate it. Thank you.
Okay... create/add custom UIView on your main view (self.view)
and set this custom view's frame = (0, 0, 320 , self.view.frame.size.height - 50) /// change value 50 to as per your requirement.
and add all of then UIControls such like textField, tableVie, button ...etc.. on this custom view.
Don't use a UITableViewController. Use a UIViewController, then add a table view and a toolbar. You'll need to implement the UITableViewDelegate protocol in code and then connect the delegate in interface builder.
I am quite new to xcode.
I am trying to create a contact details form for an iPhone using the storyboard. The problem is that form is longer than the display and I can't work out how to design it using the storyboard.
Any ideas?
Tom
In IB, you can set the controller's size in Simulated Metrics to Freeform, then select the view and make it as tall as you want. Then, add a scroll view to take up the whole view, and add your UIElements, and lay them out how you want. When you run the app, the view controller will still only be as big as the screen (obviously), but the scroll view will be as big as you made the view in IB (you may need to increase its contentSize even more to be able to scroll to the bottom).
Such forms are often made in storyboards using a UITableView and setting the "content" of the table to be "Static Cells." You can set any number of cells and the contents of the cell you want. The table itself is scrollable inside the storyboard/Interface Builder editor and looks much the way it would when presented to a user.
First, select the tableView on the left
Then, you can move it simply scrolling (on mac, two fingers on the trackpad, or using the mouse wheel)
You should have a look at UIScrollView, it is designed to support content larger than screen size (like you see in web browser or settings)
Basic usage is:
//Set a size which will be able to cover all form elements
[yourScrollView setContentSize:CGSizeMake()];
//Your scrollView now extends from CGPoint 0,0 to contentSize.width,contentSize.height.
//Your subviews should be positioned according to scrollview's bounds not the viewcontroller.view or any other container view.
//Add all the form elements
[yourScrollView addSubview:...];
[yourScrollView setDelegate:self]; //If you need actions after user scrolled etc.
Have a look at the developer manual for more info. Most method names are quite self explanatory.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIScrollView_Class/Reference/UIScrollView.html