As you can see on the image below my View Controller is packed with labels, everything looks good on iPhone SE but not on a larger screen phone. Is it possible to increase space between UI elements on iPhone 6,7,+ but keep same on SE without implementing Scroll View?
You can use Stack View, it will automatically set space for every device. Embed labels in stack view (Editor -> Embed In -> Stack View) and choose Distribution property that works for you ("Fill Equally" or maybe "Equal Spacing"). You can embed any view - also stack view (so you can have 12 stack views with label and result and embed them in external stack view for proper row spacing).
Related
I am trying to drag and drop buttons to the storyboard. The buttons seem good in my storyboard and preview like the following;
However, when I run the simulator, the button texts seem like the following;
Why the buttons are not shown to fit in the buttons of the simulator and how can I fix this?
Note: Preview and device types are iPhone13 Pro.
The iOS 15 / Xcode 13 style buttons are highly dependent on auto-layout.
Based on your screen-shots, it doesn't look like you've given the buttons any constraints.
You do NOT need to set widths or heights, but you DO want to set at least horizontal and vertical position constraints.
So, constrain all 4 of your buttons centered horizontally, and constrain:
First button Top to view Top (safe area)
Second button Top to First button Bottom
Third button Top to Second button Bottom
Fourth button Top to Third button Bottom
Then you should see them laid-out correctly at run-time.
I think it's because of the auto layout constraints. I am not very familiar with storyboards, if you don't set width of the view component, it seems fine on the storyboard but when compiling the view it actually has default size.
Try to set some constraints for width. Maybe it would help.
The first thing you need to do is to create identical buttons with identical size and with identical font size.
As you can see in your project, the buttons have different sizes, but the text is the same size in all buttons.
To make it faster - you can create one button and make a copy with option + drag’and’drop…
Then, you can put them in a Stack View. So, it will be easier for you to work with them in the future.
Select all buttons and make a Stack View...
https://i.stack.imgur.com/QLTJP.png
https://i.stack.imgur.com/OlOia.png
After that, resize your Stack View like you want.
Then, tap on a Stack View and clear the constraints.
https://i.stack.imgur.com/1pMT8.png
Fix the dimensions like this. But, without “Constrain to mergins”.
https://i.stack.imgur.com/8HKKF
After that, make for the Stack View - horizontally and vertically position in your storyboard.
https://i.stack.imgur.com/a29wL.png
The result is…
https://i.stack.imgur.com/mvQjg.png
Hope it’s break your problem! :)
Is there a function to check what device the user is using?
In one of my View Controllers I have a view inside a scrollview. In that view I have some text inputs. Then I change the height position on that view in order to prevent the keyboard from being on top of the view/inputs.
I don't need to move the view as much on an iPhone 6 compared to an iPhone 5.
print(UIDevice.currentDevice().name)
Will get you want you want.
I have a simple question and I have spent countless hours trying to figure this out.
How can I change the size of a view controller in an Xcode Storyboard for editing purposes?
I have a large form/questionnaire I would like to place on my view controller, and I simply cannot work with the current size the storyboard gives me.
Furthermore, none of the provided sizes ("Inferred", "FreeForm", "Retina 3.5", and "Retina 4") are big enough!
Does anyone have a solution to my problem?
Xcode 5.x+ (including 6.x and 7.x)
From Xcode 5 and beyond, there's a even easier solution. Inside the UIStoryboard, you can simply select your UIViewController and go directly to the fifth tab. Just change the Simulated Size from Fixed to Freeform . After that, you should see the Width and Height fields, as the image below:
Xcode 4.x (still valid for newer ones)
Select your view controller, and in the fourth tab of InterfaceBuilder, select 'freeform' in size.
After freeform is selected, you now are able to change the size of the main view inside your UIViewController. Just select the main view of the controller and change its frame in the fifth tab, like this:
To easily switch between various iOS device sizes, use a Simulated Size Metric:
Attributes Inspector > Simulated Metrics > Size:
click on 'View Controller' option on the top of the displayed storyboard and select proper size in Attributes Inspector->Simulated Metrics
You Can Change your view controller from selecting view controller, then go to file inspector.There you will see the checkbox "Use size classes". By unchecking it, you can change the size of view controller .......
Note: for the first time using of xcode
I started the development of a new app on the iPhone 5 and now I also have to add support for 3.5 inch screens. As you know, there is more space for content on a 4 screen than on a 3.5 screen.
When I run the app on a 3.5 screen, the whole layout is messed up. Is it possible to use the layout normally on a 4 inch screen, but place the layout within a scroll view when run on a 3.5 screen?
My idea was to scroll the page rather than completely redesigning it. How can I achieve that?
(or maybe it is somehow possible to design a layout for the 3.5 screen and the 4 screen seperately)?
It is totally possible to design completely different layouts for 3.5 and 4 inch screens. You would just need to add this :
#define IS_IPHONE_5 (((double)[[UIScreen mainScreen] bounds].size.height) == ((double)568))
And build separate cases, using if (IS_IPHONE_5) {do this...} else {do that...}
BUT
This should be done only as a last resort, because it would require a lot of manual/extra coding. You should ideally create the view in such a way that it automatically adjusts itself for both the screens. And you can do that in 2 ways :
1)With Auto-Layout i.e applying constraints on and between each view element. (Personally I don't like it a lot)
2)Without AutoLayout, by applying auto-resizing masks on each of the view elements. (and checking by toggling the form factor button in storyboard)
For that u need to add image of size 640* 1136 with name Default-568h#2x.png and addded to the image folder and then add the image in the Target-General- AppIcons
It very simple and it worked for me
I wouldn't suggest ScrollView since, if you go by that Method then there will be a lot of reframing of the UI ELEments
If You contain few elements then I would suggest go by AutoLayout or AutoResizing Mask, set your constraints in such a manner that they expand and contract depending on your views height,
or
If your View contains a lot of UI ELements that the constraints conflict then and only then go For Two XIb files in your App corresponding to the same class (set your ClassName to the Two Xins in identity Inspector), If you are using Story board then just Duplcate your Current View and Adjust it for iPhone 5 and set the StoryBoard Identifier different for each, and Then based on the Device height load the Views Respectively such as
if([[UIScreen mainSceen]bounds].size.height>480){
//Load iPhone 5 View
}else{
//Load iPhone 4 view
}
I have a strange problem when developing for the iPhone
There is one window (in green) and one view (in orange)
when I try to test my app it looks like this in the iPhone Simulator
you can see the view have moved upwards
is this normal? and how to solve the problem?
many thanks
You're most likely adding the view incorrectly. You could post some code and I could give you a better idea, or if you just want a quick fix, open the orange view in Interface Builder, make it 480 px tall instead of 460, show the simulated status bar and relayout your image.
In Interface Builder you can specify the simulated User interface elements. In the screenshots above you will notice in the green one you can see the status bar and the red one doesn't have it. You can turn on these elements by setting the properties of the view. Press Command-1 when you have the view selected and you will see a list of simulates ui elements you can add, these include the status bar, navigation controller bar and a few others i cant remember off the top of my head. This will allow you to position your ui elements correctly when you have these other elements on the screen.
The other issue with your view is that it is not the same height. have a look at the dimensions (cant remember exactly which one but its Command-2, 3 or 4 when you have the view selected) it should be 320x480, i reckon yours is 320x460... (20 pixels, the height of the status bar)