I am new to iOS development. I have created a login screen using xib file. I have placed the contents aligned horizontally. But when I rotate the device the alignment is going off. Not sure how to stick to the same alignment when the device is rotated.
Please refer to the images for both scenario. Any advise is appreciated.
When the device is rotated
When the device is in normal mode
There' s a constraint, in "Align" that says "Horizontally in Container"
That's what you need
u can add your fields into a UIView if you want their size to be fixed , then just add Horizontal Constraint to this UIView and set UIView size, then all elements will just follow their parent view
Related
I am attempting to customize the default LaunchScreen.storyboard of my Flutter app. I simply have a red background on the default View, and I added an Image View as a child of it. This Image View is centered on the screen and renders an image that I have added to "Assets.xcassets" with all 3 sizes. Below is a preview of what my Xcode displays:
However, this storyboard renders differently on devices than it appears in Xcode. For example, it appears slightly off-centered on iPhone 12, and it is scaled up too high for iPhone 6s and is way off-centered. See below for screenshots:
As you can see, the storyboard renders differently on the two devices. How can I make the storyboard appear the same on both devices as it does in Xcode? Any help is appreciated. If I used any incorrect terminology or need to provide additional details, please let me know as I have minimal experience using Xcode.
From the storyboard screenshot attached, it looks like there are no constraints added to the UIImageView.
You should add top, leading, bottom & trailing constraints to superview with 0 spacing to achieve what you want.
UPDATE
Above is applicable to the case when you have a small size image like 100x100 or similar that can easily fit on all screen sizes. In the comments, we see that image is way too big and we want to keep it in center while occupying 50% of screen width.
Remove the leading and trailing constraints, select the imageView and it's superview - add equal widths constraint with a multiplier of 0.5, this will make sure that imageView will always occupy 50% of the superview's width.
Also add horizontally center constraint on the imageView. Make sure imageView Content Mode is set to Aspect Fit.
I set up a Launch Screen in xcode with Inferred Size, Simulated Size: Fixed. I put a View in it that covers the whole View Controller. In that View is an image and a label. Both the image and label have height and width constraints, in addition to constraints centering both items with the superview center, yet somehow whenever I run the simulation the label is centered on the screen but the image is off to the right. Anyone know what I need to fix here? Thanks!
Edit: It turns out I had a previous launch screen file listed in Info.plist. I updated it with the new launch screen file name and it worked. I also changed the launch screen to remove the splash.
Use width and height equal to, and align your view horizontally in the container..
Also, as per Apple's human guidelines they advise against having a splash screen.
Workaround of this issue is to not place image vertically centered. You can move image a bit to top or bottom. In such way issue won't be visible.
I have created new app for iOS. The first initial page image has been added. I have checked the simulator with a different view. How should I the center of the screen shows the image, textbox and button? Please help me.
Do you know how to add constraints? What you need to do is set constraint to center screen horizontally and text box center vertical. After that apply top and bottom constraint to image and button.
You can follow http://www.raywenderlich.com/115444/auto-layout-tutorial-in-ios-9-part-2-constraints to lear more about constraints.
You can set it by giving just simply two constraint with giving height and width
Horizontal center in container and vertical center in container
I have a subview in portrait orientation (storyboard scene):
that I want to move and resize like this when the device rotates to landscape orientation:
What the best (or easiest) way to handle this should be?
I'm thinking about the following options:
Creating different separated xib files (one for portrait and another for landscape), and loading the corresponding one?
Rotating + translating + resizing the subview when orientation changes?
Directly creating both subviews (horizontal-bottom one, and vertical-left one) and hidding the corresponding according to the orientation?
I need help with this scenario, I donĀ“t find a solution that works for me. Also if I'm missing any other option, I'll appreciate to know.
Thanks in advance
EDIT: This is an app targeting iOS 7 and above. I'm not using the size classes feature, just autolayout.
EDIT 2:
Setting a new frame to the subview.
What should be the difference of this option with option 2?
Option (2) would be your best bet. Store two sets of constraints and install / uninstall them depending on the orientation.
If you were using size classes, you could do this completely in IB.
(1) is overkill, and (3) is unnecessary.
In portrait mode you have the following constraints for your subview:
Horizontal space constraints for the left, right sides
A vertical space constraint for the bottom side
A height constraint
After the device is rotated to the landscape orientation, you'll change the constraints so that you'll end up with the following constraints for your subview:
Vertical space constraints for the top and bottom sides
A horizontal space constraint for the left side
A width constraint
I am using the Interface Builder to create this UI:
And when it is in portrait the One and Two TextViews fill the width of the screen (which is what I want), but when I rotate it to landscape mode the TextViews do not take up the full width of the screen.
How can I get the TextViews to fill the width of the screen in landscape mode? In the Interface Builder, the "Autolayout" option is checked and if possible I would like to accomplish this with it still checked since everything else works best with it on. Any advice would be greatly appreciated since I am still fairly new to iOS programming.
Now the screenshots are posted below. If you notice text box One for example goes all the way to the edge in Portrait view, but not in Landscape view.
If you dont want to use AutoLayout, You can use following steps.
1) In your XIB uncheck autoLayout check box.
2) Select your TextField and set autoResizeConstraints as follows.
Tyr this .... It will help you....
You can either change the textView size programmatically when t change to landscape in the method
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
Select your UITextView and press the "Pin" button.
Click the left and right constraints so they turn from dotted light red to red.
Enter your required distance from the superview. In my example, 5 pixels.
Remember, these two constraints are not enough to define a position of the UITextView.
To do this you must either:
Pin the view to either the top or bottom and provide a height
constraint.
Pin the view to both the top or bottom
Center the view vertically in the container
Align the view with some other subview that has a resolvable Y
position