How to add 4 charts on the same form using a tablelayout.
i tried adding a chart to a container nothing comes out. please help
The charts return no preferred size so the layout code sizes them to zero. This was fixed for the next update but you probably won't get what you want here.
I'm assuming that what you want to use is a 2x2 grid layout which will give every cell exactly the same size. Alternatively you can add the charts with a TableLayout constraint that gives it 50% width/height so it occupies the space properly.
Related
I am coming across a few issues with Auto Layout when I set up my storyboard.
I want my app display to be identical (image size, spacing, proportions) on each generation of iPhone.
I have somewhat achieved the results that I want by setting each UIImageView to have central Autoresizing and an Aspect Fit Content Mode; however I cannot get the same results once I place the UIImageViews into Stack Views which I have been lead to believe is the proper way to set up this 4x4 icon grid.
Any help is greatly appreciated and if any clarification is needed please let me know.
Stack Views are here to simplify things.
You need 4 horizontal Stack Views inside 1 vertical Stack View.
Then, you need only 4 constraints in the vertical (main) Stack View: Left, Right, Bottom and Aspect Ratio (1:1).
The Stack View configurations are all the same: Fill and Fill Equally.
In my example I also added a space of 10 to each Stack View.
Like this:
Bonus: notice that I'm not using UIImageViews, but custom UIViews,
which draw themselves at runtime. You can even live-preview then in
Xcode via #IBDesignable and #IBInspectable.
Results
iPhone SE:
iPhone 6:
iPhone 7 Plus:
Take a look at the code:
git clone git#github.com:backslash-f/grid-on-stackview.git
(Please give Stack Views a chance. :-))
If the above gives you difficulty, which will not be the case, you can use a container view AutoLayout pinned to the 3 edges. Then place a https://developer.apple.com/reference/uikit/uicollectionview in the container view and set up the collection view with your data source. This is how I solved this problem in the past. Be sure to shut off the scroll, bounce, and control the amount of data source items to perfectly fit the numbers of the grid.
I'm stuck with a problem I'm sure one of you guys can help me with.
I'm developing an iOS-Application with Swift3 and what I'm trying to create is something like this:
Screenshot1
Screenshot2
The screenshots show just a part of my UIViewcontroller. The remaining space is filled with other views that are not part of the question.
As you can see the size and position of my subviews(the icon) depends on the amount of icons i'm given (not more than 8). If more than 5 icons exist it should create a second row and decrease the size of the icons to fit the space. My views should always be centered meaning they are evenly distributd to the left and right.
What i tried so far:
I created a horizontal StackView and tried to fill it programmatically but that did not solve the problem for more than 5 Views.
Tried setting up some views with auto-layout constraints but could not solve the problem of different sizes and positioning.
Of course I could do everything in code. Creating and placing all Views one by one but I would like to find a cleaner solution.
Thanks for you answers. Feedback is appreciated.
UICollectionView Can be a better option here.
Its either UIStackView or UICollectionView since they both handle the distribution of subview. Since you have a max of 8 icons I'd just use UIStackView and vertically stack two horizontal stackViews. You put items 1-5 in stackview 1 and 6-8 in stackview 2. If you need the two rows to have the same distribution then you need to put empty views with horizontal constraints equal to the imageView width to make the second stackview have as many items as the first when the number is odd.
Thanks to Shuja and Josh for leading me in the right direction.
I ended up using a UICollectionView and changing some values inside sizeForItemAt to respond to changing cell sizes and insetForSectionAt functions to center my cells horizontally.
I've been trying for days to make one layout of my app to work well, and after days of learning and mistakes I still can't get the table cell layout to look how I want it to be.
This is how my cell .xib looks like in the editor:
http://i.stack.imgur.com/VEr3r.png
And this is how my app looks like when running with suggested constraints:
http://i.stack.imgur.com/wiK1f.png
Why is that? How I can find my mistake and make the layout like it supposed to be, in the view?
Suggested constraints are rarely what I actually wanted to see.
For each label with fixed text, lock the horizontal and vertical positions either to the view or to the next adjacent item.
For imageViews, choose the size you want and lock the height and width.
For labels that you will be dynamically changing the text on, pick a size that will hold the longest string and lock the width. You'll need a vertical position constraint.
You have many options to simplify your layout.
you can use the stakview or create a static UITableView and insert your component inside the cells and enter the Constraint. excellent tutorial http://www.runtimecrash.com/2015/09/17/exploring-uistackview/
im trying to make a month calendar in swift, but im strugging with an auto layout issue.
I need 7 squares side to side, and i want to make them responsive. I have tryied to set every square trailling and leading based on the preview and next square, but it wont work without setting the width (what will make it go unresponsive). Can someone help me please?
If you know there's always 7 cells in a row (sounds like it, calendars are pretty stable that way), you want to set up a width relationship.
Set the width of the first cell to the width of the parent view ("Equal Widths"). Sounds strange at first
But then double-click on the resulting constraint in the Constraints Inspector to get the detailed constraint editor.
Set the Multiplier to "1:7"
Set the Constant to some small value to allow for inter-cell padding.
Set all the other cells to equal the width of the first cell.
I'm pretty new to the whole autolayout design and I'm trying to figure out the best way to make this design compatible on all sizes. I can't seem to find a way to space out each element so the size of each element changes according to the screen size. I know that I can constrain the subviews to the margin but Xcode seems to require a set width and height so the larger screen version ends up looking extremely compressed. (see below) What would be the best way to handle a custom form like this? Basically I need a way to dynamically space out each element.
Each element is on its own. IE text,dividers,icons
If I understood your issue correctly then I think!you need to set leading,top,tailing and bottom space and aspect ratio if necessary for change in height of textfield to the view of which you need to increase or decrease size according to its width.