Using the UIScrollView - swift

I currently have a UIStackView inside of a UIScrollView, positioned in my storyboard. I then programmatically add multiple UILabel based on user input. When the program is run, instead of being able to scroll, all the labels cram within the defined view. When the first label is created it appears in the centre of the UIScrollView, and subsequent labels decrease spacing between each other and "try" to be centred. This eventually causes the view to become overloaded. Any ideas on why it isn't scrolling? Thanks.

Related

How can I make ScrollView full screen? I placed the necessary constraints, but it doesn't work

I'm trying to make a ScrollView so that its size adjusts to the size of the text. I placed all the necessary constraints
, but when the application is displayed on the simulator, the content view starts from the safe area and also ends up to the safe area. Although I have pinned scroll view to superview and content view to scroll view.
I want the content to start not from the safe area like here ,
but from the start of the screen like here
in other words, I want to remove the blue bar from the top and bottom
Do you have any ideas how to do it?
Sometimes UITableView & UIScrollView can still show safe area even though you attach your View to top of Super View. You just need to add one line to solve this issue but make sure your ScrollView is connected to superView not safe area at the top.
Add scrollView to your ViewController and in viewDidLoad() just write:
scrollView.ContentInsetAdjustmentBehavior = .never
Check this answer for further details: Make UITableView ignore Safe Area

Move visible images in StackView closer to leading space

I have a horizontal ScrollView of 20 (110 * 130 point) UIViews contained within a StackView. Each UIView contains an image.
When certain UIViews are hidden the UIView width is maintained at 110points. However, spaces are left were the hidden UIView should be.
I have been practicing with a StackView of 3 UIViews and hiding the center UIView. This leaves a space in the middle...
I would like the 3rd UIView to move into the 2nd UIView position (middle) and perform this for subsequent UIViews later on.
Does anyone know how I could go about doing this? Is this even possible?
I was hoping to accomplish this with a UICollectionView, however, I don't think you can drag an image from UICollectionView to UIView
Drag and Drop Image from UICollectionView to UIView?
A storyboard isn't meant for these complex user interactions, so I recommend you programmatically create your stack view and then set its constraints programmatically as well. This let's you change elements' heights in your code easily. This might help you get started:
Add views in UIStackView programmatically

label and scroll view

HI FRIENDS..
I use a scroll view and a label now i want that when i scroll that , label also scroll with that and set to next location , i set paging enable = YES , so i want that there are 5 images and when i did scrolling the label i set is also move and show in other position.
thanks
To scroll a UILabel (or anything for that matter) WITH a UIScrollView, simply add the label to the UIScrollView.
You can easily do this in Interface Builder by the obvious methods.
You can also do this programmatically by utilizing the addSubview: method.
You can do one thing you change frame of label when you scroll in delegate method of scrollview or you can also make 5 same label in all 5 pages.
Good Luck
Well if you have added a scrollview on top of a uiview you can add that label on the view and then bring it to front. then you dont have to worry about changing frame of the uilabel as it will be always on top of the scrollview and at the same position and also you can change the text of that label when the user scrolls in pagecontrol value changed method.

UIScrollView limited scrollable area

I have a UIScrollView which contains a timelime. Sometimes I may only want to let the user see say one third of the view and therefore I would like it to only show this part of the scrollview but still have this nice "bouncing" effect in both ends of the view to "preview" what is outside the scrollable area.
Is there any way to do this?
I think you should specify the size of the UIScrollView to end where you want your user to scroll to but leave the size of the inner view (subview) of the UIScrollView.

Why can't I tap input elements after I resize a scroll view?

I have a sample project that uses the metrics from notifications for resizing the keyboard when a text field is focused.
http://www.smallsharptools.com/downloads/ObjC/KeyboardSize.zip
The series of text fields are all wrapped inside of a UIScrollView and when the keyboard is shown a notification is sent with the height value. I use that to decrease the height of the UIScrollView so that all of content can scroll inside without being covered by the keyboard.
But I find that when I do this the other text fields sometimes cannot be tapped. They seem to be covered with a layer that I cannot see.
What can I do to ensure that the input elements in the UIScrollView remain accessible when the height is changed?
FYI: You can see in the sample project there is a blue marker on top and another red one at the bottom. The view controller which handles the resizing is CMScrollingViewController which is inherited into KeyboardSizeViewController so that this behavior can be used by multiple view controllers.
I am hoping that this problem can be fixed so this simple code can be reused.
I figured out my problem. I was setting the view which goes inside scroll view to flex the height and width using the autoresizing mask. Once I commented out that line of code this problem went away. It seems it was resizing the view but I could still see the contents of the view but it was outside the bounds of the view so it could not respond to taps.
//self.subView.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);