What's the difference between frame and layout in Interface builder's size inspector? - iphone

In IB, there is a dropdown in Size Inspector showing "Layout" and "Frame". I know what a frame is, but I don't know what the layout is in this case. What is the difference?

When lining controls up and measuring their distances from each other it's often desirable to think about the controls' locations in terms of the visual space they occupy on the screen, rather than simply their raw frames. In many cases, the visual rectangle a control occupies, and its frame are vastly different. For example, a regular size push button looks to be about 20 points tall on the screen, with a 2 or 3 point drop shadow. In reality, the frame of a properly configured push button is 32 points tall, not ~23. This extra 9 points points of padding isn't visually apparent.
"Layout Rectangle" is the name Interface Builder uses for this concept.
The layout rectangle is useful to look at for applications of measuring and sizing. The Apple Human Interface Guidelines might make the statement that "Two push buttons aligned vertically, and horizontally next to each other should have 12 points of space separating them horizontally." This 12 points of space separating the buttons should be measured from the button's layout frames, not their raw frames.

Many built-in IB elements have a separate "layout" versus "bounds" rectangle. You can see the difference by showing them using the "Layout>Show XXX Rectangles". The drop-down indicates which rectangle the coordinates refer to.
On Mac, this impacts UITextFields that are labels for example. If you switch between Layout and Frame, the X coordinate will change by 3 pixels. I haven't played with iPhone controls to see if it impacts any of them. It doesn't come up a lot.

Related

Auto Layout Swift 4 Xcode 9 For Multiple Devices - Am I doing it Wrong?

I am having severe difficulties finding a clear working world example of auto layout on multiple screen sizes. Most tutorials have basic stuff like a button thats centralised and then after adding constraints in Interface Builder it scales with the device. One button is simple but in my example for the iPhone 4:
There are quite a lot of labels / buttons and some that are not central. The above screen shot is exactly how I want it to look on all devices.
The app is for portrait only but I want to target all devices. I tried slowly adding constraints to items from the bottom up using a multiple of the superview to position and size items and then applying aspect ratio to UI Objects (got as far as the got it button but not the red arrow buttons) but as you can see in the next picture for the iPhone 8 plus... the white space isn't going to perfectly fill like in the iPhone 4 which will leave me with a big gap at the top.
Is there a way I can change just the iPhone 8 plus layout in Interface Builder to build a layout that caters for the extra screen size?
The iPhone 8, SE and X layouts are equally awkward with extra white space.
I tried size classes but that changes it for all phones.
Is there a way to centre what I have done so far?
How do you guys position objects in auto layout that are not centred?
Am I going about it the wrong way by applying X / Y constraints using a multiple of the superview? - same for the width. I'm only specifying widths as a multiple of the superviews width then adding aspect ratio.
I just need a real world working example I can learn the basics from or a system to create for multiple devices that I can follow. I don't want to use a 3rd party library.
I really hope someone can help point me in the right direction!
Krivvenz.

How do I set specific y position, width and height without diving into code?

A designer I'm working with wants to have a UIImageView be at a specific y position, with a specific width/height depending on the iphone size. I've done research and I haven't been able to find anything online that allows me to do so with constraints on the story board. I want to avoid having to use code because throughout the rest of the app there are a lot of similar situations. In the past I've made different storyboards for each phone size to accommodate for the specificity our clients request, but I want to avoid doing this because it feels like bad practice. Is this even possible?
This can be completely handled in the Interface Builder. Follow the steps below.
1) Add your UIImageView to the ViewController
2) Set constraints for Width, Height, Vertically Align and Horizontally Align
3) You can adjust the Y position in the Size Inspector of the view.
4) Now switch to Assistant Editor and choose 'Preview' and add different screen sizes to see the auto layout in action.
All of this will set a static image size of 250x200, horizontally centered, and vertically at 1/4 of the screen height.
Little-known capability of constraints are that you can set view positions, or in your case sizes, by way of ratios against other views.
With just your image view selected, the tie-fighter :) constraints button lets you specify absolute positions & sizes: do that to set your desired y-position. But then select both your image view and its enclosing parent view, then the pop up for that same button now enables the equal height/width buttons. Add those constraints and then edit the constraint to change the 1:1 ratio to whatever ratio you need.
Excuse my lack of screenshots, posting from my phone.

Strategy to create a screen resolution independent java desktop application?

I have been been programming with java using eclipse for a few months and would consider myself at an intermediate level, and i have a vb.net background originally.
I have a question about screen resolution( in pixels) and auto-scaling my application with two parts
A) When you design a desktop application with swing( or JavaFX ) do you actually calculate the pixel width and height of every single component and then scale it up or down in code by detecting the screen resolution at startup? Scene-Builder for JavaFX, Eclipse Windows Builder Gridbag layout and GroupLayout have the facility to do it with a couple of clicks, and it is relatively easy . If it IS calculated and handcoded then that means I'll have to spend a lot of time planning ahead for each control.
B) Is there a common consensus over a screen resolution ( 1024x768 e.g.) to design the application for "initially" ( and then scaling all controls according to detected screen resolution)? My monitor has 1920x1080 resolution but I am confused which resolution should i begin designing my application in. 1024x768 seems reasonable to me.
Thank you very much for your time
I've done all my work in Java Swing, so this might not be appropriate for other GUI sets.
Layout all the components within panels and one frame.
Pack the frame.
Print out the size of the frame.
If the frame is too big, put some components in a scroll pane.
Repeat until the frame is the desired size.
In other words, I'm concerned with the functionality of the GUI. I don't care how big it is, unless it's too big for a display.
I put together an alarm clock that has a frame of 170 x 152 pixels. It sits in the lower right hand corner of my display.
I put together a clock / calendar that has a frame of 1097 X 522 pixels. It sits in the upper right hand corner of my display.
I put together a Cobol Paragraph Structure display where I maximized the frame to the size of the display, mainly so the paragraph name tree had the maximum amount of space.

How can I maintain relative sizing in Perl/Tk PanedWindows

I'm working on a Perl/Tk GUI. It will have three main areas. Two of them side by side on top and then another one below the two.
I could just use grid geometry management. The upper two would have a row weight of 2. The lower one would have a weight of 1.
This would be good for the starting position, but the user needs the ability to adjust the sizes.
Looking at the Tk documentation, PanedWindows can also have a weight, but I can't figure out how to access it.
As I have it now, with my Paned frames, the upper and left children are minimum size, everthing else fills the area below and to the right. If I adjust the main window. only the lower and right windows are resize. Worst of all, I can resize the window and make some of the children disappear.
I want to maintain the current relative sizes.
How do I do this? I'm not tied to paned, grid, pack. Whatever works.
Sounds like you are using frames in Tk. While I have never used Perl/Tk, I am kind of savy html which Tk is probably based on html. So, you might want to look into frames and framesets at Frames in HTML documents on the W3C site.
It sounds like you need 1 frameset with 2 frames for the top and another frame for the bottom.
I hope that this helps.

Dragging images from a scrollable region in Raphael?

I'm investigating the feasibility of using Raphael for a user-research project. One of the features allows for users to drag images onto a canvas and we record where they placed it. The pool of images is potentially quite large and we'll have them in a scrollable box in the tool.
I put together a quick wireframe of the issue I'm looking into since it'll probably be clearer than my explanation.
Please see the wireframe:
I'd stick with straight HTML/CSS and use jQueryUI draggables, as you mention in your comment.
You don't appear to need any of the drawing/display features SVG offers, yet if you went that route, you'd have to build your own custom scrolling behavior (instead of setting a CSS overflow-y rule) and picture layout algorithms (again instead of using CSS floats or something).
You can create a scrollable region using Raphael.
Create the viewport with fixed
dimensions (say 800x600)
Draw the images with increasing y value. After few images, the y value will go beyond 600. It will be drawn but will not be visible in the viewport.
Create a scrollbar using raphael rects. Attach drag events to the scrollbar handle rect.
When the handle is moved, translate all the images accordingly.
For e.g. lets assume in step 2, you had drawn all the images and the bottom most point of the end image is having y value 2000. Assuming the scrollbar has length 500, each dx movement of the handle will have to translate 2000/500 = 4dx. You can calculate the handle length similarly using ratios.
Since everything inside a single Raphael paper the dragging of images will work seamlessly. You will have to maintain the positions of each images.
You might find this demo similar
Remember you can always use getBBox when you drop. In this case it's rects but images would be the same..
http://irunmywebsite.com/raphael/additionalhelp.php?q=bearbones