Hiding labels in iOS without breaking the view - ios

I know we can use UIStackView in iOS9, but I'm not able to get rid of iOS8 at the moment, so I was wondering if is it possible to hide some labels inside a UIView (plain UIView, UIScrollView and UITableViewCell) and keep the rest of the visible labels "stacked".
Basically I've got some labels "stacked" vertically and pinned to each other by autolayout. If I hide any of them I get an empty space where the label was placed in interface builder.

I've managed to emulate the stackView's behavior using OAStackview, Following these steps:
Subclass ViewController using a UIScrollView and a OAStackView property.
Put the stack view inside the scroll view
Set constraints for these properties programatically
Add a bunch of custom labels to the stack view.

Related

Issue with Autolayout and StackView while using ScrollView

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

How to make a Horizontal and vertical scrolling TableView in iOS using storyboard?

here is my design structure
I was wondering about creating a horizontal and vertical scrolling tableview. I have tried a tableview inside a scrollview but I failed miserably. What to do?
I use swift4 but I wanted to do in storyboard.
The nature of content is like an excel sheet with lots of horizontal and vertical scrolling rows and columns of data.
Actually you can do this using a hack. Put the tableView inside a scrollView. Then you should give a dynamic width to the tableView by specifying a width in storyboard for tableView or any child view of that scrollView(So we get the horizontal scrolling).You have to adjust some constraints depending on your requirement
Mine worked fine but as many users have said try a collection View if its easy
Note. There is a default scrollView within a tableView, So adjust your height of tableView in a way so the scrollView of tableView work and not the parent scrollView, while scrolling from top to bottom
Instead of using TableView try using collection view, there you can use horizontal and vertical scrolling using storyboard?
Try to use collectionview instead of tableview.
If your requirement demands use of tableview anyhow, then you can use tableview within scrollview.
In tableview within scrollview approach, you need to distinguish your parent scrollview as well as tableview's scrollview. Try to differentiate parent scrollview and tableview's scrollview with different tags. Because both scrollview will call delegate methods of viewcontroller, if implemented. Just check tag of scrollview in all delegate methods of scrollview and perform action accordingly.
As per my understaing you want a view which you want vertical scroll view and horizontal inside it.
So here my suggestion is to use UITABLEVIEW for vertical scrolling and UICOLLECTIONVIEW for horizontal scrolling inside tableview
Both will work fine

Port subviews of UIView to UIScrollView without breaking constraints?

There's a view that currently has a static view that I would like to be able to scroll, because certain elements are blocked by the keyboard in 4-inch phones. However, I find that if I simply copy all of the existing subviews to be nested under a UIScrollView, the constraints are broken. I would prefer not to have to methodically set up each subview. Is there any way to convert a plain UIView to a UIScrollView?
You can use xib to create a new UIView which nested with your existing subviews, after that,you can add constraints on it as your wish .
Then useing code to add this container view to the scrollview.
I think this method should be worked.

UIStackView inside a subview programmatically

I've got a ViewController that has a lot of labels that must be displayed horizontally, so I've decided to use UIStackView for this.
These labels belong to different "sections", so I'm using nested stack views to achieve this. The problem is that one of these "sections" should be displayed with a different background color than the others.
I've read in another thread that UIStackView does not have a background color, and I should add the stack view inside a UIView and set a proper background color to it.
What I've made so far:
Create a UIView and set its color
Create a sub stack view and add some labels to it.
Add the sub stack view to the colored UIView
add the colored UIView to the main stack view.
The result: I'm not seeing any of those views inside my view controller.
Note: I need to do this programmatically.
Thanks in advance!!

UIView overlaps UISegmentedControl

In my app, I want to add a UISegmentControl on top of a UIView.They are siblings of a parent UIView.I pull a UIView to the canvas from object library first, and then pull a UISegmentControl second,but unluckily the first added UIView overlaps the UISegmentControl. What I want is that UISegmentControl is on top of the UIView. I mean UISegmentControl z-index is higher than the UIView.
The following is the screenshot.
One potential solution would be to programmatically send either the UIView to the back or the UISegmentedControl to the front in viewWillAppear(animated:) using parentView.bringSubviewToFront(segmentedControl) or parentView.sendSubviewToBack(otherView). It doesn't solve the issue of the incorrect appearance in your storyboard but it ought to fix the issue once the app is running.
1) First reduce the width and height of the overlapping view to understand its location in view hierarchy. Share your view hierarchy here so we can see in detail.
2) Delete everything from storyboard. Add UIView and then add any subviews. These 2 controls should be children of UIView in view hierarchy.

Resources