How to adjust UIView height according to the Collection View Content Height in swift 3? - swift3

I have a problem of adjusting the UIView height in my project. I illustrated the project.
Let me explain about my project image.Each Orange UIView has trailing, leading , top and bottom constraints and vertical spacing to each UIView. But, I add "Height" to each UIView because if I don't add, it gives error and add the "Height" warning.
In UIView2, I add 3 Container Views. Each Container Views has 3 View Controllers. (Data 1 View, Data 2 View, Data 3 View)
I embed Collection View inside in each views.
The problem is that in Data 3 View has many collection View cell data. So, the height of Orange UIView should be increase according to the collection view content.
Currently, I just add fixed height constant (height:800) if users click on the Data 3 segmented control button. But, I don't want to set fixed height like this.
I've been trying to solve this problem since last week. I could not solve this till now.
Can anyone help me explain in step by step please? Because I have no idea of what should I do.

Since UITableView or UICollectionView inherit from UIScrollView they basically do not have an intrinsicContentSize.
You have two ways to make the same height as the content size (the space that you can scroll):
You can subclass the collection view and override intrinsicContentSize method to return the contentSize and the sizeThatFits: method as well
Create a height constraint in the interface and set it as equal to the content size of the collection view.

Related

dynamically update color scheme of many available + refresh views in swiftui

How can I refresh a SwiftUI View dynamically while showing the user a list of color schemes to choose from? eg the user sees a list with 5 different themes each with its own button+UILabel, then presses one of them and the View refreshes with the UI elements refreshing to using that color scheme selected.
How can I force the View to redraw using the new color scheme?
Is there a way to define such Color scheme via an extension to swiftUI Color, so that I can continue to use eg a .foregroundColor(Color.primary) and yet the color actually used, to be in the dynamically chosen current theme, ie. use the Color.primary for the currently selected theme?
Thank you

Swiftui UIViewRepresentable table view having padding while scrolling

Why having padding while scrolling the table view although added Hosting cell to hold the view and create the view once time only. Any idea regarding my mistake?
enter image description here

Changing Order For First Responders in SwiftUI TextFields

I am working on a crossword app.
I have a SquareView that contains a Text and TextField, to show the number and letter for a particular square.
A 2D array of those SquareViews forms the grid of the puzzle.
I can navigate back and forth horizontally through the TextFields using the tab key, and all the highlighting works (current square yellow, adjacent answer squares blue, all others white or black).
My problem arises when I want to toggle navigation, to move vertically. I thought that the order in which TextFields were navigated depended on the order in which they were added, so I toggled between a VStack of HStacks (across clues, running horizontally) and HStack of VStacks (for down clues, running vertically). Nope. SwiftUI always moves from left-to-right, top-to-bottom. How can I change this? I learned from this forum about Introspect, so I can access each TextField's underlying UITextField and change ... it's color 😀, but that's not what I need. I need to be able to change order in which first responders are chosen.
Any assistance would be most welcome!

How do i make two QGraphicsViews scroll simultaneously?

Let's say i have two QGraphicsViews:
QGraphicsView *view1;
QGraphicsView *view2;
where view1 is big view that has vertical scroll bar(this view is guaranteed to contain an image that is bigger than viewport) and is to contain some drawing, put by user, and view2 is ruler-like view that represents y value of the according part of view1. What i want is to simultaneously scroll view2, once view1 is scrolled. I also don't want view1 to have any scroll bars. Is that possible? If so - how? Any help is appreciated.

How to resize UITabBarController content view in iOS7?

Has anyone been able to resize the content view for an iOS 7 UITabBarController? In previous versions it consisted of two views. A UITabBar and a UITransitionView. The transition view was the content view. However as of iOS 7 SDK the UITransitionView is fullscreen and setting its size does nothing.
I need to resize the content view as I want to display an ad above the UITabBar.
I managed to reach the actual content view on iOS 7 (inside the UIViewControllerWrapper) via this
UIView *viewToResize = [[transitionView.subviews[0] subviews] objectAtIndex:0];
WHen you then resize that view, you should obtain the same effect as resizing the UITransitionView.