I've been using the constraints for all objects to be aligned with each of the different screen sizes, but I want to manually set each one.
How can I manually adjust the size and location of objects on each screen size?
You can create storyboards for different sizes and load them; you can also set outlets for those constraints and set their constants.
Nevertheless, I would advise you to keep them all in one storyboard and try to adapt the autolayout to make it work for every size.
Tip: add a another navigation tab and select preview mode on this one (on storyboard). This way you will be able to see how the constraints behave in different sizes.
Related
I am working on an app that I don't want the user to be able to resize but be able to switch between 2 sizes like the MacOS Calc app.
I managed to make it un resizable using this code window.styleMask.remove(.resizable) found here Non-resizable window swift
The problem is the following, the code disables the resize button in the title bar.
Is there an option to mimic the behavior of the Calc app and if yes how?
Calculator.app seems to leave its window as resizable, as evidenced by the fact that it shows the resizing cursors at its edges. However, it is presumably restricting what size the window can be (depending on the calculator mode). An app can control that in a number of ways.
Calculator seems to implement windowWillResize(_:to:) in its window delegate to always return a fixed size depending on the mode, ignoring the requested size. The evidence for this is that the resize cursors show that resizing is possible (double-headed arrows). With this mechanism the system can't determine in advance whether resizing will work because the delegate could give a different answer every time it's asked.
Another technique is to use autolayout constraints that dictate a window size at a priority higher than NSLayoutPriorityDragThatCanResizeWindow (510).
Finally, you can set the contentMinSize and contentMaxSize properties of the window to the same size. (You could use minSize and maxSize, but the content...Size ones are easier to work with.)
To switch sizes, you can either change the zoom button's action selector to a method of your own, override zoom(_:) method, or implement windowWillUseStandardFrame(_:defaultFrame:) in the delegate. The last is probably best. It should return the frame appropriate for the non-current mode.
I am trying to make my app's storyboard universal for all Apple devices. I am having an issue with auto layout for some of my views. I am considering making a storyboard for each device since I think it will look better in the end, since I would be able to size my fonts and buttons differently for each type of screen.
What would you guys recommend I do?
Thanks
A good approach would be to use autolayouts and size classes. This approach would allow you to create only single storyboard for both iPhone and iPad. And you can easily size your fonts for different devices and also make buttons/views position/size differently for different screen sizes using size classes.
You should use size classes in which "any width , any height " is best for all layouts .
AFIK you can't just use size classes to determine the screen size and then set font sizes based on that. As can be seen when you edit in Storyboards, you can set the font sizes for specific size classes eg. compact, regular etc. but not iPhone 5, 6 or 6+. If you are wanting different font sizes for different screen sizes you could use UIAppearance to style your text elements in a centralised way or create IBOutlets to the UI elements and set the font size or other properties as required. With either of these you may still need to check the screen size with something like this:
switch UIScreen.mainScreen().bounds.size.width{
case kIphone6PlusWidth:
label.font = label.font.fontWithSize(20)
case kIphone6Width:
label.font = label.font.fontWithSize(18)
default:
label.font = label.font.fontWithSize(14)
}
Alternatively, separate storyboards for each will give you customisability but will lead to a fair amount of duplication with laying out the UI elements in different storyboards.
I'm really having tough time setting my layout right for all iPhone sizes. I have five buttons and I want them to be visible correctly for all iPhone sizes, see the screenshot. I've tried many constraints but no success. Following are my questions.
What constraints do I need to add to these buttons to fit all iPhone screen sizes?
When I change "wAny hAny" to some other settings, all my UI controls vanish. What can be the possible reason?
Do I have to start in "Any Width | Any Height" configuration to design my app for all screen sizes?
3: it's a must: start of with Any x Any
2: other then Any x Any can have custom constraint settings (like bigger Font or const. for iPad). If things change when you switch to other then Any x Any then A: your constraints are messed up B: you have custom settings (which I doubt). Neither case I would recommend to start from Any x Any , remove all contraints, and start all over until Any x Any works! then move on to detailed customization.
1: use "greater or equal" relationship between the buttons horizontally. Add fix constraints if needed on the two sides.
Remove all warnings, read about it for two weeks :)
I've got a fairly intricate IOS application with icons, tables, text fields, etc spanning across over 20 different view controllers. I built the entire application in portrait mode, and have of course realized that things look screwy when in landscape.
For the really simple screens I've had little issues using autolayout's constraints to accommodate any orientation changes. However, when there are multiple (5+) items on the screen I've found it incredibly hard to use constraints to manage everything. In fact some views look like they need the entire layout transformed to flow well.
Is there a better alternative to constraints? My only other thought is to make duplicate views, one for portrait and one for landscape. Then I can just switch on the deviceOrientationChange listener.
You can always switch off constraints by selecting the xib/storyboard file and unchecking Use Autolayout. To do this only for the more complicated views, I think breaking out into separate xibs is feasible.
Also, sometimes landscape really calls for a complete rearrangement of the view (or even adding / hiding certain elements). You should not shy away from defining separate views for this, with or without xib documents.
I have a NavigationController that stacks UIViewcontrollers that have UITableView among other UI elmeents. The tables I use are actually custom tables that use custom cell views. With this arrangement those tables don't show scrollbars of any kind even though I have configured in IB the Shows Vertical Scrollers to show them.
I've tried several ways of debugging this without success. If I print to console the value of this property (showsVerticalScrollers), it prints 1, so the property is properly set, and no, my table is not wider than its parent view, actually it's way more narrow than its parent view.
Are there reasons why a table won't show it's scrolls?... btw, this happens in iOS5 running in simulator. I'm using xcode 4.2 with SLeopard. I don't have access to an iPad to test it in the hardware but other tables I have in the same project, show their scroll bars without a problem.
EDIT
thanks for the answer... I did one last test and found that one of the causes for not showing a scrollbar is the number of elements shown in the table, when they fit in it without the need to actually scroll. Say if you have a table with 1 row and the vertical size of the table is too big for just one row?, then iOS won't show the scrollbar when bouncing.
It's hard to provide a possible solution without seeing any code, but the advice I can offer is to update your code to the bare minimum needed code to implement a UITableView and see if scrolling works, if it does, add in functionality in small increments, testing the scrolling with each new code addition till you reach the point that scrolling breaks. Incremental testing in this fashion helps to avoid issues like this where you are unable to effectively debug your application.