I would like to create a dynamically sized UITableView in Swift.
When I add a UITableView via the storyboard some content is cut off at a certain point.
Is there a way to make it possible to scroll through the content without cutting off any of it? I've thought about adding a UIScrollView, but this kind of view seems to be used for something else (e.g.: http://www.raywenderlich.com/76436/use-uiscrollview-scroll-zoom-content-swift )
At best I'd like to have a scrollable UITableView that almost fills the screen and a button that always stays on the very bottom.
Edit - To clarify what I meant by cutting off: When there are e.g. 100 elements in an array, only 10 were displayed.
But the concept of placeholder constraints solved this issue, since my array length is determined during runtime.
To have a dynamically sized UITableView, use AutoLayout. https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/Introduction.html
Yes its possible to not cut your content, but how is your content cutted ? Could you link a screenshot about it ?
You didn't talk about your constraints, did you set yours correctly ?
For example, you can set them like that for :
UITableView:
UIButton:
UITableView is a subclass of UIScrollView, your link show a specific usage of UIScrollView options (Paging), but it is not the default behavior of this component.
Here is an example: http://spin.atomicobject.com/2014/03/05/uiscrollview-autolayout-ios/
Related
I am trying to achieve a certain layout that looks like twitter and many other apps. Some people do it in UIVIewLayouts but I want to achieve it using this way (if possible ). As you see in the attached image. I have Header, and cells in the collectionview.
While scrolling up I want to minimize the imagview avatar inside the headerview. -> ( ViewForSupplementaryEelementHeader )
while scrolling down, I want to make the top UIImageview to be fixed to the top and stretchy
Thank you all in advance
*ps I am doing all of this in code nothing with storyboard and I dont want to use it at all.
Please advise me how to access these imageview while scrolling up and down.
I think this is the example you are looking for
https://github.com/sunlubo/StretchyHeaderView
This will add only tableview in storyboard...other all the work is done through coding
I'm trying to develop something like CSStickyHeaderFlowLayout but customized for my table, but I'm not sure how can I achieve this goal. The idea is
Someone can give me a hint how achieve this objective?
To add to Vollan's answer, to make the title stay still you could use a view that contains two subviews: the first is the scrollview (with the image and table as Vollan suggests) and then add another view (like a UILabel) for the title. Thus, while the image and table scroll in the scrollview, the title will stay still.
Best solution would be to wrap everything inside an UIScrollView. That will allow you to scroll to bottom of the screen and then only scroll the tableview. That way it will appear like the tableview will overlay the image.
While using a tableview within a scrollview would likely work, your tableview would have to always be it's full size (without some annoying constant re-sizing), so you'll lose the value of the enqueuing/dequeueing that makes tableViews work so well.
The CSStickyHeaderFlowLayout has example pretty similar to what you want to do, did you look at their examples? You may be able to play with it and get it to do what you want If your problem is simply having a constant title, you can just add a view above the table or use the NavBar and adjust the contentInsets
You might also consider using a collectionView instead. It's much more flexible as far as layout goes.
Instead of the standard dots that Apple provides for a page control, I want to have something like this. However I don't want it to be in an infinite loop were you can circle around. All I care about is the scrollable text on top, not the parallax image.
Currently I have a paging scrollview that contains three view controllers so my custom page control will have only three words: Main, Today, Settings.
The way I see this being built is the following:
Subclass UIView and insert three UIButton's and evenly space them. The title of the buttons will be Main, Today, Settings.
Insert this UIView as child of scrollview (or maybe not)
Make UIView the width of the iPhone screen
Not sure about here now -> as you scroll the scrollview shift the UIView on and off the screen so that the UIButton will be centered in one of the view controllers in the scrollview.
Am I on right track or does anyone have a demo to this?
Yes. You are on right track. You can use scrollView for this exact purpose. You have to make use of scrollViewDelegate methods for this. The below link will explain you how to do that.
How to make Paging with scrollView.
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 would like to insert a UITableView into a UIScrollView.
To do this I added a ContainerView inside the UIScrollView and a UITableView linked to this ContainerView.
The result obtained in the storyboard is this :
http://i.stack.imgur.com/12hZz.jpg (Storyboard)
http://i.stack.imgur.com/AGY4L.jpg (Storyboard)
When I launch the emulator the TableView is loaded correctly, but not with the result expected
http://i.stack.imgur.com/ebij9.gif (Animated GIF)
http://i.stack.imgur.com/bEO8B.jpg (Wrong result)
But instead what I wanted to to obtain is this:
http://i.stack.imgur.com/R7Zhb.jpg
Is it possible?
Could you tell me if the way to proceed is correct?
Thanks!!
I have not enough reputation to post images and more than two links.
Sorry for my poor english.
So what you have is close, but you need to set the size of the container view to the content size of the table view once it has loaded its data. Your other views around the content view then need to respond to the change in size so you don't get overlaps.
If you know the height of each row in the table and how many there are then it's easiest to calculate the hight required and set that as the size of the content view. If you don't, or the height can change based on user choices or something like that, then you will need to do something more complicated which observes the content size of the table view and updates things when it changes.