Update UIView inside a UIScrollView using Autolayout - ios

I'm stuck on this problem since 2 days and I don't know how to proceed & I didn't find a solution on internet so I'm going to ask advices here.
My problem is about AutoLayout, UIScrollView and UIView : Please take a look on the schema I made to explain you what I want to do.
The blue box represent labels, the green box the UIScrollView and the Pink the UIView. The UIView contains a chart (using the great iOS-Charts library). The thing is, when the user scroll to the right, I add data to the chart and it becomes longer, no problem with that.
But as soon I add constraints, nothing is display.. And I would like to give the possibility to the user to see this in landscape.
The hierarchy is :
• View
• ScrollView
• LineChartView
So what constraints should I add to do that ?
Thank you very much

Based on the coments I have elaborated an answer:
First Step:
Right click from child ScrollView to parent View
Second Step:
Chose these constrains (You can select multiple at once by holding shift key) then tap on Add Constraints:
Third Step:
Drag with right click from scrollview onto itself and it will pop another message:
Forth step:
Tell him to keep current height( you can add here different constraints but it will do it for now)
As for the child UIView you can do the same and see after that what happens.
To be able to scroll please note that after you modified the size of the graph containing UIView you must also set the UIScrollView contentSize to match the graph UIView size.

Related

Xcode Interface Builder Pin Tool makes UITableView disappear

I have a UITableView and I want it to hit the upper bar, the sides of the view and the Seek Bar below. When I add constraints with the Pin Tool, the UITableView simply disappears and I get no log output.
I use the Pin Tool like shown here:
After this, the table disappears. Why? Here is another picture of my setup, it's literally just up/down/left/right constraints, nothing else, what am I doing wrong?
Solved it by giving the top bar some constraints and giving the UITableView a "width" constraint - I have no idea why that works but now it scales nicely for every display size

Custom Page Control with Paging Scrollview

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.

Fitting a tableView into its parent UIViewController

I dropped a TableView into my ViewController using Storyboard and I want it to be filled without any margins like the lower ViewController with TableView in the image below.
I tried some suggestions from the answers in other similar questions but didn't work at all.
Some say I need to set PIN. and I tried it like below:
I've typed '0' for all 4 constraints but this is what I got:
This AutoLayout thing makes me really hard to layout things automatically, unlike it's name.
What should I do now?
Just Click on Resolve Auto layout Issues after that click on Update frames as shown into below image.
In the Document Outline, tap the yellow arrow:
Tap the yellow triangle:
Then select Update Frames, Fix Misplacement.
This will fix the misplaced view. Alternatively you could have resized the table view before specifying the constraints.
I recommend you have a look at an auto layout tutorial, for example link.

Extra space on top and bottom of Init View Controller

I have a swift app I have been working on for some time now. I noticed that my init view controller has extra space at the top and the bottom of the view, so much that it allows me to pull up and down on the first view and let go and have it spring back into where it was. I removed all my constraints thinking I had an issue with them, but it's still done the same thing. The size class is set to any any, and all my graphic fit inside the view, yet I still an able to pull up and down.
I also made sure my view, wasn't a scroll view, it's not.
I looked around for similar issues, but couldn't find anything like this.
Thanks for the help!
Here is what my view looks like in IB
When I run the app.
Showing the amount I am able to pull it down from the top.
If you remove all of your constraints, and the storyboard is set to use auto layout, it usually won't show up correctly, as you have seen. You will have to add the constraints to each element in your view controller. To do that, you can control click on each and drag it where you want to connect a constraint. Or, use the pin and align buttons in the bottom right corner of the storyboard view.
There is a good tutorial from apple that I suggest you read. It will help you with the basics of using auto layout. Another option would be to not use auto layout. To turn it off in the Storyboard, go to the file inspector and uncheck the box "Use Auto Layout".

How can I make/program a UIlabel to scroll horizontally upon user input?

I'm making a simple calculator in iOS, and I want the user to be able to scroll the label horizontally when the end gets truncated.
How would I go about doing this? My original idea was to make two buttons that would move the label left or right by using stringpadtoLength type of method, but that seemed inefficient.
I see two ways of building this.
Use a UITextView and always return NO from -textFieldShouldBeginEditing:. This should get you 90% the way there very fast.
Build a custom control using a UIScrollView which contains a UILabel that uses -sizeToFit. This will be a bit more work, but will do exactly what you expect.
I went for Jefferey's second suggestion because I thought it would give a "cleaner" result. Turns out, it's not that easy to implement. Here's what you have to be careful about when you're putting a single-line UILabel inside of UIScrollView, in order to be able to scroll horizontally through the text.
The parent UIViewController should have the box "Adjust scroll view
insets" unchecked. If you forget this your text may be placed below the content of the UIScrollView, meaning that you can only see it if you hold it while over-scrolling down.
Call [self.toolboxItemNameLabel sizeToFit]; in your UIViewController's viewDidLoad in order to set the right size for your UILabel. This ensures that the scrolling is comfortable, going from the left to the right of the text.
When using autolayout, you must add constraints for the leading and trailing space to container of the UILabel which is inside of the UIScrollView. Thanks to this great post for the answer.

Resources