I am working on the auto layout. However, there is a small problem about I can not figure it out. Google it but can not find the clue.
As we can see, the tutorial first created uitextfield1 without any constraints at all. However, when I am trying to drag and drop another uitextfield2 to the view, there is constraints associated with it
My question is how to create an uitextfield with no constraint ( width + height )
Edited (for more details what I am trying to achieve)
For the picture above, we can see the textfield2 has the width constraint of 203. However, the textfield1 does not have width constraint like below
all the components in the view has there own constrains, but Xcode only shows you the ones for the selected component. If you don't want the Autolayout constraints in a view or Storyboard then disable it in Xcode
Related
I recently ran the updates on xcode9 and I'm getting blank space on the right side of the screen(about 10px) for every view controllers when I run on the simulators. Is there anyone getting same errors?. I didn't set any specific constraints. I uploadad on github just in case. Does anyone know how to solve this problem?
storyboard
After looking into your project, I noticed that the table view of SingleViewController (on the main storyboard) does not has the appropriate constraints, also its size and origin are incorrect. What you should do is to edit the frame (from IB size inspector) of the table view to be:
instead of:
Also, you should setup the appropriate constraints for it:
Select the table view and tap "Add New Constraints":
Note that I added four Constraints: top, lead, trail and bottom with 0 values.
That's should fixed your issue.
Also, I would recommend to setup constrains for all of the other views in your project to avoid such an invalid layout...
How to design the following layout with StackView
I know that it can be easily created without using stackview but is it possible using stackview because i have lots of ui which already designed using stackview how can i add divider between views like above image
For that i set the following constraints
**But run time it shows like **
You can use some simple Autolayout constraints to get this kind of interface with a UIStackView.
The below image describe the hierarchy and constraints that you can apply:
Also the Accept and Reject buttons have Equal Width constraint.
Output screenshot:
You can do that using UIStackViews, here is how:
First, create a subclass of UIView to use as the class of the UIView in between the 2 buttons.
class CustomWidthView: UIView {
override var intrinsicContentSize: CGSize {
return CGSize(width: 1, height: self.frame.height)
}
}
You only need to override intrinsicContentSize.
Now, add your 2 buttons and an empty UIView between them, and set the class of the UIView to be CustomWidthView. Embed your 2 buttons and the view between them in a stack view, and set the position of the stack view properly using the appropriate constraints.
Select the stack view and from Attributes inspector, find the property named Distribution and from the drop down menu next to it, select Fill Proportionally.
To reflect your changes in the UI Builder, select the custom width view and go to Size inspector, go down to the bottom of the list and you'll find a property called Intrinsic Size, change its value to be Placeholder, and from the width drop down menu, select 1.
There may be a better way to achieve this, but this is the one I found for now and I'd like to find a better one.
Since UIStackView uses auto layout to arrange its subviews, you can modify its behavior by creating constraints.
I assume you have three views in the stack: the accept button, the divider, and the cancel button.
Create two constraints:
An equal-width constraint between the accept button and the cancel button.
A fixed-width constraint on the divider (presumably setting its width to 1).
See also this Q&A.
I'm trying to create simple application (for testing purpose) with NSScrollView and 2 multi-line labels inside it (title and document). I can't use integrated TextView because I need 1 general scroller to scroll all content, not just for one selected TextView.
So generally I need fixed one-line title and document text with shared scroller.
I have no mind how to make this.
I've attached my sample project (only Storyboards) with scoller, you can take a look here: scroller.zip
I'm not sure if this is possible in the designer, but it is possible to set correct constraints in the runtime.
Follow the steps:
In the storyboard select your text field
Set bottom margin constraint (28 in
your example)
Set height constraint (242 in your example)
Connect the height constraint to an outlet in the viewcontroller (for example #IBOutlet weak var labelHeightConstraint: NSLayoutConstraint!)
In the viewcontroller's viewDidLoad method set constraints height to expected height (for example
labelHeightConstraint.constant = 1000)
Run :)
Hope it helps!
I do have autolayout on, but for some reason my center button isn't being centered for other phone sizes. I have constraints set and like I mentioned autolayout, so I'm somewhat confused. All other items are where they should be, buttons, other labels, etc. One specific label at the top is just off center for all models aside from iPhone 6.
If I am not wrong you didn't add any constraint to your label that's why it is not at center.
Add this constraint for label.
Result for all screen:
i'm just adding video and setting constraints with rightclick on the outlet and selection done with left click
this is tested in all the device so just watch and apply you can solve your problem and if you want to arrange your view so you can add new constraints which is required otherwise you can set these 4 constraints set and execute.
just watch this video and setting your constraints
you tube link to setting constraints in autolayout to centering button
I have a table view with prototype cells. Currently I have only added a label to the cell. When enabling edit mode, a delete button will appear animating the cell smaller but the label doesn't reposition. This used to be no problem with autoresizing masks but now I can't seem to get it to work.
Does anyone know how I should configure auto layout to have the label positioned inside the cell when in edit mode?
I searched some more and found that it is necessary to remove the horizontal spacing constraint that Interface Builder adds, as this is relative to the UITableViewCell and not the contentView and then add a constraint which is relative to the content view.
You can read more about this in this answer to a similar issue.