I use popover using storyboard:
wR * hR variation is given for the iPad and it is not following the ipad constraint:
According to the variation the font size of label should be 47 but it is 17.
enter image description here
We can change this by code but I want this through storyboard.
I am expecting a solution through storyboard not by code.
Related
When I run my app in simulator, the height and weight still get for my storyboard preview choose phone.
Should not be choose which kind of simulator?
ex:
storyboard preview choose iPhoneSE then the image view
weight = 96
height = 92
storyboard preview choose iPhone8 then the image view
weight = 112.5
height = 108.5
but when I storyboard preview choose iPhoneSE and simulator no matter choose which like iPhone 8, iPhoneX...
weight = 96
height = 92
Why?
Most weird thing is the same simulator when I choose different storyboard preview, I get different size...
print(self.img.frame.height)
print(self.img.frame.width)
I had this exact same issue, and I do not think it comes across well in the description above. To recreate it, take the following steps:
Setup:
1) Start a new 'Single View App' in Xcode. I am currently using Xcode 10.2.1
2) Go into Storyboards and add a UIView object with some sort of backgroundColor so that it is visible
3) Give this new view some auto contraints, such as a leading, trailing, centerY, and an aspect ratio of 1:1. Just make sure to not give it a fixed height or width.
4) In ViewController.swift, add an IBOutlet variable such as 'myView' for this UIView and connect it so that it is easy to reference.
5) In viewDidLoad(), add a print statement to the effect of,
print("Bounds of myView: \(myView.bounds)")
Testing the issue:
Now, back in Interface Builder, set the preview, or 'View as' at the bottom to something like 'iPhone SE'. Then, at the top, where you choose the simulator, also choose 'iPhone SE'. Now run the app.
In the console, you will see your print statement with the bounds of the view, and everything will look fine visually.
Now, change the Interface Builder's preview 'View as' option to something like 'iPhone 8', but keep the simulator option on iPhone SE
Again, run the app in the 'iPhone SE' simulator.
Just like before, visually everything is okay thanks to autolayout. However, the bounds information printed in the console is different. This instead matches the 'iPhone 8', or whatever device was chosen for preview in Interface Builder.
For an even more obvious example, choose something like an iPad Pro for the Interface Builder, and again run it on iPhone SE simulator. Again visually everything is okay, but the bounds information in the console is way off. It is tied to the Interface Preview and not to the device being tested.
The problems arise when you are writing code which uses the bounds information of an object under autolayout constraints which do not have a fixed width and height.
Solution:
In ViewController.swift, add the following after the viewDidLoad() method
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
print("Bounds of myView in viewDidLayoutSubviews: \(myView.bounds)")
}
Now, no matter what preview option we use in Interface Builder, the simulator logs the correct bounds information at this point in the lifecycle.
So, for any projects which make use of the bounds or frame property in code for such a view as the one in this example, should place any code refrencing that bounds within the viewDidLayoutSubviews() method.
if you added the leading, trailing, top and bottom constraints you will get different size of the imageView on different screen sizes and if you want the imageView to have a fixed size on every screen then you can use centerX and centerY constraints for positioning and add constant width and height
Example 1
Example 2
adding imageView width and height
adding centerX and centerY constraints
Explanation
in Example 1 image width and height will be dynamic and in Example 2 height and width of the imageView will be same no matter which device is used to display
Trying to achieve UIStackView with 2 labels for iPhone and 3 labels for iPad using size classes.
View hierarchy
Default size class
[UIStackView]
[UILabel 1] [UILabel2]
[UIStackView]
RxR size class
[UIStackView]
[UILabel 1] [UILabel2] [UILabel3]
[UIStackView]
It looks exactly as expected in Storyboard as you can see in the above screenshots but on simulator iPad view is messed up.
iPhone Output (okay)
iPad Portrait Output (messed up)
iPad Landscape Output (messed up)
What's happening in iPad?? Is it a bug or I'm missing something?
Thanks.
I have created a sample project.
Follow below steps to achieve your requirements :
Drag one horizontal Stackview in to your interface builder
set it's constraints like : top,leading, =trailing and fixed height
Drag and drop three labels in to it and select all together and set one constraint : Equal width
now select second or middle label and from attribute inspector click on + button beside installed and select Regular for both width and height. It will add regular,regular variation and uncheck the checkbox for that R,R variation. Refer below screen shot for better understanding,
And you are done! now you your center label will not show in iPad and every label will be displayed in iPhone!
See below result screenshot of iphone and ipad in my case!
iPhone :
iPad :
Update :
If you want two to hide label in iPhone and show in iPad then add one more variation : Compact Width Regular Height for middle label and uncheck the checkbox to uninstall. Refer below screenshot,
It seems you are hiding one of the labels on iPhone using the "installed" checkbox in Interface Builder. Using the "hidden" checkbox instead seems to solve the problem. Which I guess is a bug.
I'm working on app and will for 1st time use auto layout/size classes. Today my first day learning it and I understand constraints now and how to place the images where I want them to be on every devices from iPhone 4s to iPad PRO.
As my main storyboard in Attributes inspector i'm using INFERRED size. In show Assistant Editor, Preview, i'm using all device sizes.
In my inferred storyboard i'm using a UIImageView size 170 Width, 230 Height. Then I use AutoLayout to make it center of every device screen in preview.
Now the issue is this UIImageView covers HALF of the size of iPhone 4s preview but only about 1/5th the size of iPad PRO. How do I alter the size of each UIImageView to the size that I want them to be in each device without changing that centered position of each UIImageView in the preview devices?
You need to first set up your constraints properly and then choose the type of scaling you want.
Set up your constraints:
Click on the Pin icon |-[]-| at the bottom of the screen. Turn on all four orange I-beams. Set the four constants to zero.
Uncheck the Constrain to margins checkbox and click 'add 4 constraints'
Then set your scaling:
Click on the Image View you added to your View Controller.
In the Attributes Inspector on the right, choose your image.
Set the Mode of the View to Aspect Fill (fill entire screen cropping top/bottom or left/right as necessary) or Aspect Fit (letter box image so that entire image is shown uncrossed).
That should work
Maybe you can use a pending or proportion constraints instead of width and height constraints.
In Xcode 5 there was an option which let us see the View how it will look in 3.5inches and 4 inches screen.
as highlighted in the red circle. i can't find this option in Xcode 6
Fist of all you select View Controller than click on attributes inspector size field is show select your size see below
You can adjust your storyboard size like 320X480 3.5 inches and 320*568 4 inches.
Click view controller change your simulated size just change freeform and give width and height size .
I also new in Xcode 6 and I also faced this problem , now I identify my self Storyboard in different views using the following method.
goto attribute inspector - size - select your screen size is inferred to iPhone 3.5 or ....
I have a scroll view in a storyboard and the app is to run on iPhone4s and iPhone5s with iOS5 and iOS6.
I initially created the storyboard and was running on an iPhone5 and now I'm testing with an iPhone4.
Isn't there a way of just using a single storyboard for both the iPhone4 and iPhone5 and the when views etc. will automatically resize themselves depending upon the device, or do I have to use two separate storyboards?
I've tried numerous things, such as changing the simulated metrics size and many others but I can't find anyway of the view changing its size automatically - as I created the storyboard initially for an iPhone 5 the view now seems stuck at a 548 height when loaded. SUrely there must be a way of specifying in the storyboard that its height comes from the device? (Its height is the full screen less the status screen).
Further details
There is UIScrollView inside a UIView, the UIView will resize, the UIScrollView will not:
Yes, you can do it in the "Size Inspector", inside the Utilities menu. There you can set the autosizing and origin of any visible element.
This works in iOS 5 and 6 and it's not required to use the Autolayout, which is only for iOS 6.
Size inspector:
Second screenshot:
You have to use two storyboards for iphone4 and iphone5. Then you can check the device size to load the .xib according to it.