How to use autolayout to make a dial pad in iOS? - autolayout

The requirements are:
Buttons that number from 0 to 9
Buttons should be evenly spaced from each other, and fit any screen size

See the screenshots to get how can it be done.
I've kept width constraint and height constraint constants of NumberPad View to 300 and 400 respectively. You can change these constants and the number buttons will automatically adjust accordingly. Let me know if you want more clarity.
Views:
Animated Views:
Constraints:

This solution might not be so great if your buttons have a background color, mine was clear.
I laid out the 10 buttons in a 4 x 4 grid, with button 0 taking up the entire row on the bottom.
I started by pinning the 0 button to the left, bottom, and right of the container.
I then pinned the top left corner button, the 1 button, to the top and left of the container.
For the 2 button, I pinned to the left of the one button, and the top of the container.
For the top right corner button, the 3 button, I pinned to the left of the 2 button, the top and right of the container.
I made the 2 and 3 button have equal widths and heights of the 1 button.
I repeated this for the remaining buttons, but made sure to make the heights and widths equal to those of the 1 button.
When I finished at the 9 button, I pinned the 0 button to the vertical space above with a constant of zero.
I updated the frames, and was happy with the result.
I made sure to make sure all the pinning had a zero constant.
I searched high and low for a solution on Google and Stackoverflow, and couldn't find anything ideal for me, so I decided to do it on my own, and just contribute an answer for record keeping, while helping anyone else out in the process.
Let me know if you have any questions.

Related

Position jQuery Mobile popup allways 20 pixels below top position of visible area

I´m working on a tool only for tablets (Android, iPad) based on Cordova and jQuery Mobile (1.4.5). In the first phase of this tool, many of the users who have to work with it were asking for some more comfort regarding the behavior of the form popups.
The problem was:
As a user came to one section, I provided him with a collapsible-set, consisting of sub-sections. In this sub-sections, the user gets data-grids with Add, Edit and Delete buttons next to each data-set.
So, as the user tapped on Edit button (or Add), I opened up a popup with the necessary form and form-elements to edit this data-set or add new data to the database. But in many of the upcoming popups the amount of the form-elements is as high, so the popup appears higher or even much higher then the collapsible-set (including the data grid) behind the modal popup is.
The popup of jQuery Mobile is centered by default and even if I positionTo origin and pass x and y coordinates to it, the library/widget wants to position the popup to this coordinates by the center point, rather then the upper left corner.
Users always had to scroll around to come to the start point of the form and after submitting the form, they had to scroll up again to where they tapped on the button to open the popup.
Now I tried to do everything I could imagine, to force the popups top position to 20 pixels below the top position of the visible area on the tablet, regardless of where I am, when tapping on any Edit or Add button.
I was playing around with offset() (window.pageYOffset), etc. and set the position of the popup by:
popup2open.popup('open').css({'top':popupTopValue+'px','left':popupLeftValue+'px'});
In fact, the popup is positioned to exactly where I want it, if the top offset is between 0 and 100. On all values above 100, the top position of the popup increases by absolutely incomprehensible value. The only consistent fact is, that the more I scroll down before I tap on a button, the more this value increases - so it does not in/decrease by random.
(BTW: I found out that I have to set "popupLeftValue" to 0, so the popup is positioned in the center horizontally.)
I just can´t see any regularity on increasing value...
Can anybody give me a hint or a punch to the right direction?
Thank you in advance!
PS: I experimented also with .css({'position':'[fixed|absolute]','top':popupTopValue+'px','left':popupLeftValue+'px'}); and that worked well. Only to find out one show-stopper: If I set the focus to an input-field inside the form and than closing the virtual keyboard on the tablet, a reposition-event is triggered and by this, the popup is re-positioned massively below the former position (in fact around 300 pixels below and just marginalized to the right border of visual area). The Cancel and Save buttons are even out of scroll-able area.
(some more funny fact, btw.: if I set the focus to the same input-field, than not closing the virtual-keyboard but directly setting the focus to a select element and after this pressing the back button of the tablet to escape the select menu, no reposition-event is triggered...!?)
On 18th of July 2013 Gabriel Schulhof added this line to a feature-request from one user, who asked exactly for what I´m struggling around with:
"We are indeed considering adding such a feature..."

jQuery Accordion multiple column not behaving accurately

Scenario: I have created a simple 2 columns jQuery accordion with 56 <li> elements. In reality it may have 200 or many more items who knows ;) It's repeating <li> in a loop
Try the fiddle. It's cool! https://jsfiddle.net/srmahmud2/smtn6gt0/9/ demo here
Way I have done it: made li float left, with 15px padding to make some space in between.
Target: Make a proper behaved multi column jQuery accordion
Problem:
For example the clicking on number 1 item on the left will expand but most of the items form left will automatically go to right which is not desired.
Now click on number 3. While expanding and after finished expanding this will again come back to left. So you will not have it under your mouse pointer to click again to collapse or click again to expand any of its child items. Try all the odd number before the last item.
Clicking on any items on right before the last item will expand it; but this will open a white/blank space on the left as well.

Evenly distribute objects within another object [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Is there a simpler way to even distribute multiple objects within the bounds of another object?
I've included a picture to help illustrate what I want done.
The green portion is my artboard, the gray portion is the main body and I would like item1-6 to be even distributed within the bounds of the white box. Typically to achieve the desired result I have to create additional objects (represented by the red lines) and place one at the left end of my box, one at the right end, and one between each item, and then use the distribute evenly button and remove the red lines afterwards.
I imagine there is a faster way but I can't seem to find it. Any ideas are appreciated.
Okay, this is slightly fiddly, but hopefully this will seem quite inuitive once you've done it once or twice.
Short version;
Find the width of your container.
Select container and objects - then set container to Key Object.
Enter width of container into Align window: Distribute Spacing, divide the figure by the number of objects, then click Horizontal Distribute Center.
Group your objects and center them to your container. Ungroup them again, if desired.
Long version;
1. Work out the width of your containing box (or artboard, if you are distributing your items to that). If, for example, you have a rectangle you can simply select it and look at the 'W' (width) value at the top of the window (click on Transform to reveal the info if you're working on a smaller screen). Just remember this number - nothing else.
2. Select all of your items AND your container. Click on the container again to make it the 'Key Object' (you should see that its selection edge becomes distinctly fatter).
3. If necessary, open up your ALIGN window (Window > Align). With the window visible, you should see three rows or sections from which to choose - 'Align Objects', 'Distribute Objects' and 'Distribute Spacing'. If the latter is missing, you may need to click on the little up/down arrow symbol next to the 'Align' tab title a few times in order to expand all of the options.
4. Ensuring that you still have all of your items selected and your container set as the Key Object (The 'Align To' box should automatically be set to 'Align to Key Object' in recognition of this), enter the container width you took note of earlier into the 'Distribute Spacing' box - and append /x where x = the number of items you have. So, if your box is 200 pts wide, and you have 5 items, you would enter 200/5 - this will just save you having to do the maths. Illustrator will automatically divide your starting figure and (in the case of this example), it would change to 40 pt (200 divided by 5).
5. Now click on the Horizontal Distribute Center button and all of your items will be set to the correct spacing. They probably WON'T be properly aligned with your container, though, so ...
6. In order to prevent your nicely spaced items being messed up by the next step, DE-SELECT the container (so only your items are selected), group them together - either with the keyboard shortcut CTRL+G (or COMMAND+G on Mac), or by going to Object > Group.
7. With the items grouped, re-select your container (so container AND group of objects are selected), make the container the Key Object again - if you don't want to see it move) and click on Horizontal Align Center. Your items will now be properly centered in your container and can be safely ungrouped if you wish (Ctrl+Shift+G / Command+Shift+G).

wxpython not showing the entire grid

I have a wxpython csv reader. I am displaying results on a grid. The grid will take about half of my screen. I would like to display 100 rows at a time. I assign there to be 100 rows but I can not scroll to the bottom 50. I have proved that the rows are there by writing to the rows that I can not see then copying the whole column and pasting in excel. What I am expecting to see is a scroll bar that allows me to scroll to the bottom 50. I allowed editing of size of column. When I increase the height of the column, the scroll bar appears,but still only allows me to view the top 50 columns. (if user makes column height a inch bigger than normal, my scroll adds an inch) My best guess is there is something wrong with the way I am initiating/getting the best size of the combinations of sizers,panels,and the grid. I have cut out the code that not needed but the layout panel and box are my overall/main panel and box.
import wx.grid as grd
import wx
self.layoutPanel = wx.Panel(self)
self.layoutBox = wx.BoxSizer(wx.VERTICAL)
self.previewPanel = wx.Panel(self.layoutPanel)
self.previewBox = wx.BoxSizer(wx.VERTICAL)
self.resultGrid = grd.Grid.__init__(self, self.previewPanel,0)
self.resultGrid.CreateGrid(105,20)
self.previewBox.Add(self.resultGrid,0, wx.GROW)
self.resultGrid.SetSize(self.resultGrid.GetBestSize())
self.previewPanel.SetSizer(self.previewBox)
self.layoutBox.Add(self.previewPanel,0, wx.ALL)
self.layoutPanel.SetSizerAndFit(self.layoutBox)
self.layoutPanel.Layout()
The problem was nested somewhere in having 2 panels in side one another. This is normally "ok" to do but it is a little more complicated with the grid. I got rid of the previewPanel and previewBox completely and that solved the problem. However another problem was the FIT. The fit makes the panel as small as possible which is not what I wanted to happen. In code not shown I had re-sizes occurring and when I did this I had setSizeAndFit which took the scroll away. I changed it to setSize and the scroll bar stayed.

Resizing main window: how do I know which side is used for resizing?

When I resize a window, I can do so using the top,bottom,left or right sides or top-right,top-left,bottom-right or bottom-left corners.
Is there a way to know which one is used when I'm resizing?
I don't know if there is an elegant solution because different operating systems handle borders differently.
My suggestion is
to compute the difference between the current and previous window size each time it is drawn
Get the mouse cursor's position.
If the window X changes, the border used is probably the left or right -- whichever the mouse cursor is closest to. If the Y changes, probably the top or bottom border the cursor is closest to.
If both change, the corner the mouse cursor is closest to is probably it.
A few corner cases may come up. For example, a window can be resized on some systems using the keyboard. It can potentially also be resized programatically, like when the user changes to a resolution too low to contain your window. These things can be handled in most cases by detecting of the mouse button is clicked while the resize is taking place.
Also, it is possible to resize just the width or height from the corner. In these cases, you may have to choose a threshold for mouse distance from corner that would decide whether it is actually at a corner.

Resources