I have a question while developing iOS application using Xcode11.4.
This is my first time to developing iOS, sorry for my stupidity.
Storyboard development is too hard to me.
This is what I wanna make.
The way I did is make a stackview and put two textviews in stackview.
And it's not problem so far.
< My storyboard >
There is vertical margin between textviews, so I tried to set them to zero using View inspector.
But it is not working, and Xcode displaying constraint error.
Is there any better way to set margin to zero between vertical TextViews?
Thanks.
Select your stack view > now select attribute inspector which is showing with blue icon in this image
now edit spacing as you want
Related
I am having trouble pinning the UIButton to the bottom of my UIViewController, (There is a tab bar if that helps).
Here are the constraints of the UIButton.
Originally, it all worked fine, but ever since I added iPad support to the application I have issues. on the iPad the UIButton is pinned to the bottom of the screen, directly above the tab bar. However on iPhone, there is this empty gap at the bottom.
What I Tried
Doing some research I saw that sometimes split view controller causes a grey bar, I added this line of code to resolve it and it fixed the bottom bar , but this constraint issues is still causing me a headache.
self.extendedLayoutIncludesOpaqueBars = true
iPad View Hierarchy
iPhone View Hierarchy
You have an option on Xcode to vary your constraint depending of the size of the screen.
You can create two constraints, one that works on iPad, one that works on "classic" iPhone.
Here, if I create a new constraint during the variation, I can then select on the right window which variation you want the constraint to be installed on.
There is a whole topic about that here
Remove current Constrain and Try unchecking "Constrain to margins" button.
Try setting a constraint to a View instead of a SafeArea
1- Give it a constant height for example 40
2- While setting constraints, uncheck (Constrain to margins)
3- Give it a proportional width constraint with the super view 0.8
Note1: If you don't want to give it a fixed height you can do the same step 3 but with height and not 0.8 but maybe 0.2 to less depending on your design.
Note2: You can use a scroll view, it will make it so easy for you
I'm working on my first swift app and I found out quickly that I need to use constraints to properly layout my page. So far I'm running into two issue.
The first one is that after adding some constraints, my view is pushed off the screen on the storyboard, but it looks fine(outside of my second issue) in the Assistant editor.
My second issue is that on some phone sizes the constraints are causing the text fields to expand when viewed in the Assistant editor and on an iPhone 6s test device.
I've added some screen shots below. Any help with this issue would be really appreciated.
Each time you add a constraint in storyboard, it is not automatically applied to your working view. You may think it should be applied immediately, but try to think think like this. If you have a view, and you apply height constraint (for example) and if Xcode applied it automatically you would get a view of width 0, since you haven't applied width constraint. That's why you need to tell Xcode to update constraints explicitly.
So when you want to update constraints, select view you want to update and go to Resolve Auto Layout issues, and click on Update Frames. This is located in the bottom right corner of your storyboard. It looks like a small triangle between two lines. Here you can update all views or just selected views.
For the second issue, you need to apply fixed width constraint to your stack view, instead of adding leading and trailing constraints. By doing that stack view will have the same width on each device.
I have read through several tutorials and stack overflow posts about this but I can't get it to work.
Here is what I'm doing:
Create fresh Xcode project
Add Button to center of default view in IB
Make sure size is set to Any, Any
click align button in lower right corner to Add New Alignment Constraint
Check box for Horizontally in Center: 0
This works as expected. However, if I copy and paste a button from an existing project, and go through the same steps, I encounter problems.
For example, if I resize to a compact width, the new, copied button is not centered, and instead has a +100.5 next to its constraint.
I have compared the settings of the two buttons and they are the same.
What is the issue here?
I have a number of views from an old project (xcode 5) that I would not like to create, but all elements have this issue.
Just for future reference to this issue, the issue was related to not adding constraints on the second screen. One easy way to do that is by asking Xcode to add suggested constraints for you.
When you drag your button in the middle of screen, you can see that Xcode gives you some hints and shows you horizontal and/or vertical lines when you move the view in the middle of the screen. You can make sure that the view is in the middle of the screen if you can see both horizontal and vertical lines:
And then you can ask Xcode to add missing constraints for you by tapping the first item in the lower right, and choose Add Missing Constraints
For more information on Auto Layout and how to use it, I would suggest checking out Auto Layout sessions in Apple WWDC sessions.
I'm making an app in which I add people to a list by using a modal VC, that currently has only three text fields.
Problem:
This is what I see in the interface builder, inside my Main.storyboard file:
I'm running Xcode version 6.2 (6C131e) and the app I'm making will be for iPod touch only, so I disabled auto-size classes. I'm expecting those text fields to be at the center of the screen (same distance from text field lateral border to screen edges). Instead I get this on the simulator:
Question:
How can I set an equal distance for both the sides of text fields? Any resource like tutorials, examples, guides are appreciated, because I am a very beginner in iOS programming. If this can be done with interface builder for me is better then programmatically.
As simple as this:
In the Align menu from the bottom of interface builder if you set this constraint to 0 it will be the center of the view
Select First Textfield
Goto Pin-> Uncheck constraints to Margin-> Select Top,Left,right constraints with default value(or change if want ex. 16 left,right,30 top).
For Second and Third Textfield
Goto Pin->Uncheck constraints to Margin->Select Top,Left,right constraints
If you are not using Autolayout then the default Autoresizing property should be
Change the Autoresizing property to this :
Check this question : Any other method to resize views, other than Auto-layout
I just take horizontally as example. You have two ways to make it in the centre.
1. Make leading space equals trailing space.
Make the textfield center horizontally in container view.
I recommend you can study with raywenderlich tutorial.
http://www.raywenderlich.com/50317/beginning-auto-layout-tutorial-in-ios-7-part-1
After adding my launch image using a xib (and I even tried the traditional launch image way as well) some of my view controllers have a strange right margin now. For example before I might have had a label whose width was the entire screen, and used auto layouts such that it was leading/trailing to the content margins, and now despite that after adding a launch image there is a margin (it's not on every screen, but definitely some). On one of my screens where this is most prevalent i'm using autolayout but overriding with constraints that I add programmatically. Not sure if that's related.
Has anyone experienced anything like this or does anyone know if adding launch screens affect the story board / view controllers in any way?
Thanks!
On the launch screen select your image view, then select the pin at the bottom right of xcode (3rd option). Make sure all constraints are set to 0, while making sure the red I is selected for each one when they are set and uncheck constraint to margins. Finally click add constraints :)
Hope this helps you!
Rachel