Change viewController's height as textView height changes - ios

I have a viewController with a textView inside a scrollView in the viewControllers view. The textViews scrollEnabled feature is set to false and I have the textView height resizing as text is entered. This works perfectly until the textView height becomes larger than the viewControllers view height. I have the view height set to freeform and know you can set it to a different height. However, I have other objects int the view and want the view to load with its initial default height and then to resize as the textView height changes and then the user can scroll as that height changes.
Is this possible?

it's not clear what you are trying to do, but if you want to know more about UITextView an it's delegates, you need to study how UITextView works:
UITextView *textview
It's already a UIScrollView, it inherits from UIScrollView, right? and UIScrollView inherits from UIView.
You need to know that a UITextView is a special view with properties like frame (from UIView), contentOffset and contentSize (from UIScrollView).
And in the inheritance you have all the delegates for UITextView (UITextViewDelegate), for UIScrollView (UIScrollViewDelegate). Inside those delegates you have a lot of methods to determine some of the information you want to know.
But, I don't understand what do you need anyway.

Related

UIScrollview Height dynamic based on views ios

I'm writing an ios application, which has child views (like fragments or subviews) which are placing in a simple UIView in a UIViewController and the height of UIView is approx 300px. Im just loading subviews in UIView, however every subview has its own content that may not be fit in 300px thus uiscrollview cannot got though out the last view.
My problem is, Im unable to solve the scroll view content in order to scroll from parent UIViewController along whith its child view controller subviews, as the subviews are longer than 300px and thus uiscrollview is unable to get te last element.
I tried to to give static scrollview.contentSize.height = 1000 and hence the scroll view can scroll below the screen but im unable to click on the later views as it seems uiscrollview is unable to read that element.
My question is, how can i assign dynamic uiscrollview height assuming that im using autolayout in my uiviewcontroller and I want to calculate scroll height according to children based in my UIViewController. Im using swift 2.0 and autolayout in storyboard.
Your constraints should be like,
scrollview - top,bottom,leading,trailing
view (content view) - top,bottom,leading,trailing,fix height and horizontally center in container
and add your all other stuff in that view. you will got desired result. it will scroll in small screen size then content view and will not scroll for bigger screen then content view.
second thing you need to increase height of your content view as more subviews add. your content view's height should be equal to all subview's height and spacing
After this setup if you unable to scroll then check content view's bottom constraint's constant in size inspector. make it zero (if unable to scroll then only).
hope this will help :)

Enable scroll view scroll if text view is long

I have a scrollView which contains textView. If text is long and does not fit on a screen, I would like to increase textView height (which I think I could do by adding NSLayoutConstraint outlet and modifying it, correct me if I am wrong) so that view would be scrollable (or non scrollable) depending on text length.
Pretty much, like I can set Scrolling Enabled for textView, except I wan to scroll whole view because of images and labels I have on that view.
EDIT. Basically - how to guess textView height based on string, in order to have proper size textView
To make your scrollview content scrollable you need to set the size of your UIScrollView content ( your textview ), e.g. use:
scrollView.contentSize = CGSizeMake(textview.frame.size.width, textview.frame.size.height)

UICollectionView cells not showing when I set the height too low

I'm trying to add a UICollectionView to my view to use as a scrolling date picker on a single line. I'd like this to be relatively compact, but I'm having trouble when setting the collection view's height in IB.
Basically if I drop the height of the frame below 114, my prototype cells disappear, and no cells are displayed when I run the app. As long as it's above that value, everything works fine.
I've also got a black bar of empty background space above the cells despite setting their height to the same as the frame's height in sizeForItemAtIndexPath.
My delegate and datasource are set up correctly, and my cell has an identifier set and is being dequeued just fine, as long as the view's height is large enough. Do I need to subclass UICollectionViewLayout to get a really short view to work?
Uncheck Adjusts Scroll View Insets on your view controller or set automaticallyAdjustsScrollViewInsets property on the view controller to false programmatically.

When shoud I set the contentSize of an UIScrollView that is embedded in a cell of an UITableView?

(Note: The content of my Table's cells should be scrollable left-right, while the table, of course, should be scrollable up-down.)
When the UITableView's cell is initialized, the metrics of the UIScrollView (which is a subview of the cell) aren't layed out yet, so saying customCellSrollView.contentSize = CGSizeMake(364,44); has no avail.
What I found: Subclassing my UIScrollView, I can override - (void) layoutSubviews and inject the size adjustment by simply saying customCellSrollView.contentSize = CGSizeMake(364,44);.
Works, but feels hacky.
Is there a better way? Is there an automatic feature to set the UIScrollView's contentSize to the bounding rectangle of its subviews? That would be practical.

Dynamic TextView with storyboards and auto layout

I have a view which has on top a UITextView then a series of other views. The idea is to resize the Text View on its content size and to move up all the other views.
I have set all the constraints in storyboard and if I change the height constraint value of my TextView from there, all the view updates fine.
On runtime I can resize the Text View frame to fit it's content size, but the rest of the view doesn't change. So I'm guessing I don't have to change the frame but only the height constraint.
Any suggestion on how is it possible to do this thing on runtime?
How can I change the Height constraint value in code?
Is there any way to "link" a constraint to the controller from storyboard?
Thanks for helping
Make an IBOutlet of height contraint from nib to your .h file.
Lets name it textViewHeightConstraint
self.textViewHeightConstraint.constant = textView.contentSize.height
U need to set a textviews property Scrollable to false

Resources