I'm having a problem with UITextViews, in particular I would like to have a textview which is not scrollable (only showing text), but the content that is shown changes when the textview resizes:
In both images the textview is the same size (frame) but for some reason it cuts properly after it is resized post-load.
Some background:
1) this problem only occurs in nested views (it the textview is directly in the view controller it is fine)
View controller
-> Custom subview
----> text view
Here is the code for the custom subview to reproduce the issue:
https://gist.github.com/pfaucon/6f7c2ba0328ce38cb22b
The problem was that I was not calling [textView sizeToFit] when I set the frame the first time (but I did every other time).
Related
I a trying to create a UIScrollView that fits exactly the contents of its subviews. I do this with a StackView and the scroll view's height is determined by how much content there is in the stack view. Within the stack views, there are views that contain an UIImageView and a UITextView
The UIScrollView starts below the title view, however every time I want to add another view (which it should scroll when the content is bigger than the actual frame) there is an issue with the scroll view's Y position. This works perfectly if I only add UILabels and UITextFields, using the same procedure
How can I do it so I can programmatically add views on the stack view that includes an UIImageView and a UITextView, just as the View Controller with labels and textfields does.
You can download my app project at the following url
https://github.com/francisc112/DescriptionWithImageApp.git
Instead of a scroll view why don't you use a table view and create a custom cell with the stackview and its contents inside the cell and you can dequeue the same cell for adding multiple information.
I was not able to open your project
So I Tried opening your StoryBoard and Re-Viewing your constraints Applied , here is what I have Done Please check in following Link
Link - https://drive.google.com/file/d/1D-dzKsSqpx7dWsI5fYRdAfCMY_vENoIR/view?usp=sharing
View Hierarchy
Note - For such output I will prefer using a TableView instead of StackView as Same output can easily be achieved using TableView
I have a problem with a UITableView not detecting touches.
In an iPhone-only app, I have a UIViewController, which containts:
UIScrollView
UIView (let's say a content view)
Some labels
UITableView (last)
The labels have a dynamic height, because they contain some text that I must retrive from the web, so I'm using auto layout.
I'm setting the content size of the UIScrollView inside the viewDidLayoutSubviews method, and I'm doing this by summing UITableView.frame.origin.y and its height.
Here comes the problem: when the labels contain only some words and the UITableView does not exceed the iPhone screen size, everything works ok. But when they grow, and the UITableView gets pushed down, when I scroll down I can't click on the cell anymore. Also, if when loading the view the table is half visible and half not, I can click the visible cells, but if I scroll down, I can't click the others.
I'm using swift 2 and Xcode 7.
Here is an example:
Clickable:
Unclickable:
Do the following thing:
yourView.clipToBounds = true
Now, if UITableView does not appears means your UIView is not same bigger to hold down UITableView.
Make sure that your UIView height is bigger to hold the contents in it and then try to tap on it.
Updated:
If you are using AutoLayout, then do the following thing.
Give the fix height to UIView
Take the outlet of height constraint of UIView
Now, in viewDidLayoutSubviews change the constraint of UIView to UITableView contentSize height.
self.heightConstraint = self.tableView.contentSize.height
Let me know, if this helps!
Adding some info to the #Rémy Virin's answer here:
From Apple Documentation, you shouldn't embed a UITableViewinside a UIScrollView.
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.
Addition:Solution Since you want to scroll the content above table also, the one solution is place a Header View for the Table and place the Content over there to make it Scroll along the Table View.
If you use Autolayout, no need to specify contentSize to UIScrollView as it will automatically expand by taking the height of its subview.
In your case, increase the height of the Base UIView (content view as mentioned by you) which holds the tableView when the tableView height increases.
UITableView becomes unresponsive when it extends below its container view.
I Have a UIScrollView in my ViewController and ContentView in UIScrollView.
There are various other Views in the Content View to make understanding of the used labels and textfields more readable
Here is a screen shot to help you understand the hierarchy of the viewcontroller
All the Constraints are set properly I can see the views as they are aligned in storyboard on all size of devices, userInteraction is enabled on all the textFields and UIViews (I triple checked) still I'm not able to edit text on the textfields that are not immediately visible on the screen when the view controller is launched.
i.e. If the first three UItextFields are visible when the viewController is launched (4.0" device) they can be edited or if the first Five UItextFields are visible when the viewController is launched (5.7" device) they can be edited while the rest do not respond to user interaction
I've checked if they are in any case are overlapped or not by changing the background color of all the Labels, TextFields and Views. Nothing is overlapping anything, all are where they should be.
Content Size is set for scrollView in viewDidLayoutSubviews
-(void)viewDidLayoutSubviews {
[self.scrollView setContentSize:CGSizeMake([UIScreen mainScreen].bounds.size.width, 1724)]; }
The Height 1724 will never change no matter the size of the device on which the code is running
Please check your contentview size or setbackground color for scrollview and contentview. Contenview size is not increasing i think.
I have spent at least 10 hours trying to figure this out and I am stuck. I am trying to have UITextView within a UITableViewCell that automatically expands to the size of the textview when the number of lines in the text view has changed. The table cell is inside a static table view. I have looked at almost every question about this on stackoverflow and nothing seems to be working.
My test project is here.
I have created a custom class that automatically resizes the textview. It works perfectly when not in a table cell. You can see this in the example project. There are two instances of the textview; one in a regular view where the textview resizes correctly, and another in a tableview. In the table cell, it doesn't resize until the second character on the next line has been typed. It is odd, because when I log the height of the textview it says that the value of frame.size.height has changed but the text view does not change size.
One thing that worked was creating a custom table cell and then overriding the layoutSubviews method but the problem with that was the bottom border line on the table cell lagged and created an ugly line across the screen. I looked for a solution but could not figure out how to prevent this.
Thank you for taking the time to read this.
I have tried your project and make it work by :
In Tbl View Controller in storyboard, remove AutoLayout. Although you don't set any constraint for the text view, at run time some constraints will be set automatically, and that will clash when the text view tries to change its frame.
In storyboard, set the autoresizing mask of the text view to default (Fix top, Fix Left, flexible right margin, flexible bottom margin).
It will work correctly now.
I have a view in which I have UITableView (grouped style). In the Interface builder, I am resizing the UITableView so that it looks like a small portion in center of the screen.
But when I run the application, UITableView takes up the whole area of screen and does not look like the small portion in center of screen (which I had set in Interface builder).
I tried to resize the tableView programmatically in the viewDidLoad method as tableView.frame = CGRectMake (0.0,0.0,100.0,100.0), but still the tableView occupies the whole area of screen.
Please help.
Regards,
Pratik
Sounds like your table view's got autoresized. Try to fiddle with the autoresizing settings.
If your table view is the main view then it will automatically fill the whole view controller's space regardless of the autoresizing settings. In that case, make an empty UIView as the root view and put the UITableView as a subview of it.