Dynamically increasing height of content view of a scroll view in ios9 - uiscrollview

I am struggling with this stuff for a few days. I am having a view controller in which I have a scroll view and above it a content view. In the content view I am displaying some text from web in a label. I am using a view controller of free form size 600*1000 for my designing purpose.I have given the following constraint to my content view -
1)pinned to the edges of scroll view.
2)content view width equals to superview width.
3)content view height equal to 900.
My scroll view is working perfect.
So now I want that whenever my text increases then my label size would increase thereby increasing the height of my content view automatically. So how to do so. Any answers are most welcome. Thank you.

Set the number of lines for your UILabel to 0.
Add leading, trailing, top and bottom constraints to UILabel.
Set number of lines to 0 does the trick, as the content increases UILabel will automatically adjust the height.

Related

IOS Auto layout not displaying the UILabel in multiple lines when content length is longer

I am trying to build a screen similar to twitter/instagram profile page where there is a header section and below that scrollable content.
I have a view controller which has a table view. I wanted to include a header view on top of the table cells. So i dragged and dropped a "View" just above my cell and it works fine. Now i have a label inside this header view and i want the label height and UI view height to adjust automaticlly based on the content length of the label. (If the content is a long string, the number of lines of label should automatically increase and the container view(headerview)'s height should increased based on it's content items property.
I tried to set auto layout on the table(top left right and bottom to the container view(headerview). But then the label is shown in single line, truncated at the very right corner. If i remove the bottom constraint from my constraints, the label appear in multiple lines, but the container view(headerview)'s height is not increased, thus producing an overlap of the label on top of the table below that.
I have the number of lines property set to 0 for the label.
Can anyone share some ideas how to do this ? I am using Xcode 7 and swift 2
There are several approaches for what you want to accomplish. If you do not care if the header scrolls with the cells, the easiest way is to do something like this:
----------------
Header
Label
TableView
----------------
You should pin your header Top,Right,Left.
You should pin your tableView Right,Bottom,Left.
You should pin Header.bottom = TableView.top.
You should pin your Label 4 sides to it's superview(Header).
Set Label numberOfLines = 0
If your header has a fixed width, the label will automatically inherit that width, and setting numberOfLines=0 (a.k.a unlimited number of lines) will make your label increase it's height. Because your label is pinned to it's superView by it's 4 sides (and the header has no fixed height), your header must increase it's height to match the label height.
Hope it helps!!

NSSplitViewController gives child view different size each time the app starts

I'm using Autolayout & NSSplitViewController to develop a OS X app with two split views. But every time I run the app, the split views have different size. Sometimes it shows:
But sometimes:
What I want is the left panel have a min width of 150 and an initial width of 200. The right panel have a min width of 200 and take the rest space at the initial time.
What I do are followings:
Add a NSSplitViewController and set it as the window content of the NSWindowController.
Resize the left panel to the width of 200(which I want to be the initial width, but it seems not working), and add a Table View to it. Then give the table view a min width constrain of 150.
Add a Custom View to the right panel and give it a min width constrain of 200.
Set the holding priority of the right splitViewItem to 249.
Set the view outlet of the SplitViewController to the split view.
Here's my Xcode screenshot:
The code are here: https://github.com/luin/sample-NSSplitViewControlller

iOS fixed width dynamic height scrollview with autolayout in xib

I was creating a scrollview contains an image view and a dynamic height label,
here's my hierarchy in xib file:
-> view (originally existed view when xib file created )
--> scroll view
---> content view
----> image + label (dynamic height depend on its content)
I set the content view's height depend on the label's height
,and then set the scroll view's content size(scrollable area) to the content view's frame size
I expect the content view and the scroll view both has equal width to the top view
(top view's width is flexible when device got rotated, and also are the content view & scroll view's)
and only the vertical direction is scrollable.
yet I totally have no idea dealing with the autolayout,
once I set the content view's constraints to the top view, the scrolling becomes disable,
but after I remove all constraints the content view'd be scrolled like a bouncing block...
(sorry for not providing any picture but only description for my question due to low reputation)
been mad about this for a whole day
any help would be appreciated.

How to ensure NSOutlineView inside a custom view renders full height (without scrolling)

I have a window with two custom views stacked on top of each other. I use auto layout constraints, as follows:
Top view leading, top, and trailing edges are tied to superview.
Bottom view leading, bottom, and trailing edges are tied to superview.
There is a fixed vertical space constraint between two views.
Bottom view has a fixed height constraint.
Top view has a it's compression resistance set to 751.
So far so good. The idea is that the bottom view height is fixed and as the window is resized, the top view height adjusts to compensate.
Both top and bottom views have other views/controllers loaded in, as appropriate. The bottom view ends up containing an outline view with a half-dozen entries. I would like that outline view not to scroll. In other words, I would like to automatically adjust my bottom view fixed height constraint to match the height of the outline view required for it not to scroll.
Ideally, I'd prefer to solve this with auto layout without having to write code. But, if that's stretching beyond what auto layout can do, code help would be appreciated as well.

View based NSTableView with each view contains 3 labels with should resize based on Text

I need to create a view based tableview in Popover as specified below:
Tableview should be placed in Popover(Popover height should be same as tableview).
Each row should contain a view.
Each row view will contain 3 labels.
Labels should be auto re sizable based on its text height.
Based on 3 labels height, Cell row height should resize.
Based on all cell rows, tableview height should resize.
Based on tableview height, Popover should resize.
I have done this in a static format, but i need to do it in more dynamic format(in future i should be able to add more rows using same classes and methods).
Main problem i am facing is, i am unable calculate the size of cell view in tableView:heigthOfRow: since i don't know the text of labels in this point of time.
So i just created tableview cells in loadView itself and saved in array, and fetching from array in tableview delegate methods. But i think this is wrong way of doing so.
Note: All data to tableview will be given while loading the view itself. Labels are not editable.
Cocoa system resizes the subviews based on superview ,I think scenario that you are looking for is to resize super view based on subview size.
Following 2 solutions i can suggest right awyay,
1.You can choose to post notification upon size change in each subview and make immediate superview observe that.
2.Use globals for size of each subview in your case 3 labels, and have an API to calculate finalRect in your view of view based table view.
Hope this helps:) have a nice day.

Resources