AutoLayout in Xamarin for scroll view - ios

i have an issue that is driving me mad! I am trying out Xamarin for iOS app development. My issue is the do with auto layouts and constraints, i have a simple UIView inside a scroll view, i cant get this to resize on both ipad and iphone. The scroll view also leaves a margin above the view of constraints. Anyone had any issues with this?

1 - Add constraint to the child UIView inside the scroll view: Bind Top, Left, Right and Bottom.
2 - Set fixed Height to the child UIView.

Related

Not able to add scroll view to the existing view

I am trying out the scroll view in my learning iOS. I added one main view, in that i added few sub views. Then i embedded that main view to scroll view. I also tried to set content off set value in my view did load. But scroll view is not scrolling.
Then i added through programmatically, but my main view was not coming in center. Still i can move my main view. Which i dont want. I want my view to scroll , i dont want any scale or move left or right.
Here is my code : Link
Any solution or help would be great. Not sure why i was not able to do. I can do with table view or collection view. But i want to do in my main view.
Thanks
I have found multiple issues in your codes and I have done some tweaking and the scroll view is working perfectly. Okay, let's talk what I did :
I did it through storyboard so,
I commented your code in viewDidLoad.
In main.storyboard, I added the scrollview just below your header view and gave a constraint 0,0,0,0 (top, leading, trailing and bottom)
Now I dragged your main view inside the scrollview and gave a constraint 0,0,0,0 (top, leading, trailing and bottom) and equal width constraint to the scrollview.
I added vertical stackview with distribution fill inside the mainview and gave a constraint 0,0,0,0 (top, leading, trailing and bottom)
Check if this is working or not!
There is some issue with the constraints of the scrollview in your application because of that your scrollview is not scrolling. To add scrollview properly to the exiting view you should follow this link:-
Add a ScrollView to existing View
Or if you want it for specifically for swift 5 then follow this link:-
How to add Scroll View in Swift 5?

Scrollview not working properly on iPad in xcode(iOS)

Recently, i've been building and app which requires a scrollview, for all the content to fit. I've had a few difficulties creating my scrollview. I've tried a few different methods for building it, but ended up building it in storyboard with autolayout. I've set the height of the view controller to 1000, and therefore also the simulated size to freeform. The width of the content view inside the scrollview, I've to the same as the view which contains the scrollview.
The hierarchy goes like this:
-View controller scene
-Top layout guide
-Bottom layout guide
-View
-Scroll view
-Content view
-Label with text here
-Constraints
-And so on
I've been replicating the process in this link, to create the scrollview:
https://www.ralfebert.de/snippets/ios/auto-layout-recipes/uiscrollview-storyboard/
When running the application on the simulator, I get the following result:
The scrollview is not working properly on the iPad. It seems like the scrollview doesn't adapt to the changes in the width, which happens when its ran on an iPad, since it's bigger. When the app is ran on the iPad, the scrollview stays the same width as if it were shown on the iPhone.
This is how it looks in the editor. The view controller on the left is the view controller which has the scrollview implemented, and the one on the right doesn't. The first image shows the storyboard, when I view it with the iPhone 8, and the second image is when I view it with an 9,7" iPad:
It would be greatly appreciated if anyone could give me a hint to whats going on!
EDIT:
Left side is what it looks like, and right side is what it should look like:
Add the UIScrollView to your main view
Set Top, Left, Right, Bottom constraints all to Zero
Add a UILabel inside the scroll view
Set number of lines to Zero
Set Top, Left, Right, Bottom constraints all to Zero
Set the label's width constraint equal to the scroll view's width
That should do it :)
This will keep the label's text aligned to the top of the scroll view. If you add enough text to fill more than the full screen, it will scroll vertically.

Xcode Scroll View Auto Layout Issue when Embedding with Navigation Controller?

I seem to be having issues when it comes to embedding a scrollview within a navigation controller. So here are the steps I take, and its really easy to replicate the weird error i seem to be getting.
1.) Drag and drop a UIViewController
2.) Followed by a UIScrollView
add constraints to UIScrollView, 0 on all sides, uncheck constrains to margins.
3.) Drag and drop another View into UIScrollView
add constraints to UIScrollView, 0 on all sides, uncheck constrains to margins.
Control drag from view into scroll view, make same width and height
After the following steps you will see in the following images that the view is not following the constraints I set, for some reason it thinks 0 is +64 from the top of scroll view? Not sure what I'm doing wrong here as it is very annoying visually.
In your view controller's attributes inspector, look for the Adjust Scroll View Insets and Extend Edges Under [Top|Bottom] Bar options.

UIScrollView disappears when adding constraints

I have a UIScrollView that contains everything else in my ViewController. I use it because I have logic to scroll up the view when the keyboard shows.
I'm working to make my view compatible with variable screen sizes to accommodate newer iPhones. Currently there are no constraints on anything in the ViewController. If I open the app on a device, it appears in the top left corner.
The first thing I tried was pinning the left/right sides of the UIScrollView to the edges of the container, with left/right distances of 0. When I fired it up on a device, the view had disappeared entirely.
I then tried adding a Horizontal center in container constraint the scrollview (removing the other constraints). Again, just a blank screen - everything had disappeared.
What am I doing wrong? How do I make my scrollview fill the screen, or at least be centered on wider devices?
Is there any way to debug layout issues like this? At the moment, I have no insight into what has happened to the view.
Adding height/width constraints, even though these constraints were overridden to stretch the view to the viewport, fixed this problem.

Scrollview implementation with autolayout for a Universal App using xcode 6

I have been struggling past few days to implement a view that is scrollable using autolayout in Xcode 6.0 for Universal Apps. I have looked at many examples. However I am not able to get this working.
I am implementing this way:
View
--ScrollView
---ContentView (This view has all the subviews)
----- Labels
----- TextFields
----- Buttons
----- TableView
----- ImageeView
Setting the constraints of ScrollView to the View as zero for all the four edges. And constraints for the ContentView to ScrollView similarly all zeroes. Then I am adding constraints to each control setting the height and width. And the first control has the Center Horizontally and the last Control has the constraint to the Content View.
I can get the screen working if I don't add the scrollview. It is pretty confusing..
Unfortunately this does not resize on the iPhone. I am using .Xib for the Builder Interface. Please help me with an example or please guide me to any information that I can use to resolve my issue. Thanks in advance.
You can't create the scrollView contentView in the xib file.
You need to add then dynamically.
After you set the scrollView autolayout constraints in code you add all the objects:
1) set the contentView size (this could be as big as you want,don't need to set constraints to the contentView)
2) add the objects you want (labels, views, button...) to the contentView by calling
[scrollView addSubView:<your subView>];

Resources