nslayoutconstraint

Prevent Interface Builder from auto creating Constraints?

混江龙づ霸主 提交于 2019-12-04 03:09:14
问题 I created a demo project here. I have a view where I created a ScrollView in a .xib file. In interface builder I did not set any constraints. In my viewDidLoad method I set constraints with SnapKit: scrollView.snp_makeConstraints { (make) -> Void in make.edges.equalTo(self.view) } When I run the code I get the following console output: Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each

Xcode auto layout constraints - why defaulting to negative padding?

▼魔方 西西 提交于 2019-12-04 02:59:28
I am simply adding a UIView into the main view of a view controller. I want the height to always be 64px, but the width to stretch to the width of the screen. However, when I go to add constraints, the left and right padding default to -16, even though the view is stretched all the way across its parent view. Even if I set these back to 0, when I run the app the -16 padding is added back in. What is going on here? Uncheck "Constrain to margins" checkbox in the pin menu (the first image in the question) while adding spacing to nearest neighbor for the new constraints. 来源: https://stackoverflow

Trailing and Leading constraints in Swift programmatically (NSLayoutConstraints)

若如初见. 提交于 2019-12-04 02:08:57
I'm adding from a xib a view into my ViewController. Then I'm putting its constraints to actually fit it override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) ... ... view!.addSubview(gamePreview) gamePreview.translatesAutoresizingMaskIntoConstraints = false if #available(iOS 9.0, *) { // Pin the leading edge of myView to the margin's leading edge gamePreview.leadingAnchor.constraintEqualToAnchor(view.leadingAnchor).active = true //Pin the trailing edge of myView to the margin's trailing edge gamePreview.trailingAnchor.constraintEqualToAnchor(view.trailingAnchor).active =

add constraints programmatically swift

本小妞迷上赌 提交于 2019-12-04 00:17:59
I am trying to add constraints to a facebook sdk login button. I have the button inside a scroll view and I am trying to add a top constraint to a label that is also in the scroll view. I am able to successfully add the height constraint with no run time errors but the actual constraint does not seem to be applied to the button. @IBOutlet weak var orLbl: UILabel! @IBOutlet weak var scrollView: UIScrollView! override func viewDidLoad() { super.viewDidLoad() var loginFBButton = FBSDKLoginButton() loginFBButton.readPermissions = ["public_profile", "email"] let heightConstraint =

What are gray constraints in Xcode view hierarchy debug view?

試著忘記壹切 提交于 2019-12-03 23:40:38
I know what the solid ones are: I created them myself. What about the gray ones? Implicit, maybe via size-to-fit? The gray height conflicts with the solid height. Where do the gray ones come from? You are inspecting an object such as a label that has an intrinsic content size. The intrinsic content size generates height and width constraints; that's what intrinsic content size is . The constraints in gray are showing you the constraints that the intrinsic content size generates. If you just look at them, you can see that: they say "content size"! They are in gray because they are overridden by

Understanding “firstBaseLine” vs. “baseLine” AutoLayout Constraint

折月煮酒 提交于 2019-12-03 23:25:13
I've created the following view that looks as follow: And used Add missing constraints t automatically add constraints. I am pretty new in iOS world and I'm trying to configure out how constraints work. On document outline, I can see the added constraints: I click on label UR and Size inspector show me following: What is the difference between constraints aligned by first baseline to UL and aligned by baseline to UL? When I click on the size inspector on constraints button, it shows me the same line. naomimichiko From the Apple Docs: NSLayoutAttributeBaseline The object’s baseline. Available

Catch UIViewAlertForUnsatisfiableConstraints in production

风格不统一 提交于 2019-12-03 23:17:14
Is it possible to catch autolayout constraint ambiguities in production – the equivalent of a UIViewAlertForUnsatisfiableConstraints breakpoint but for production apps? My goal would be to add a global handler that would report such errors to a logging system. The symbol UIViewAlertForUnsatisfiableConstraints actually is a function : _UIViewAlertForUnsatisfiableConstraints(NSLayoutConstraint* unsatisfiableConstraint, NSArray<NSLayoutConstraint*>* allConstraints) . It is private, so you can't replace it. But it is called from private method -[UIView engine:willBreakConstraint

ios change constraint programmatically

限于喜欢 提交于 2019-12-03 16:52:09
I am using autolayout with a constraint. The top space to superview is 100 I now want to change this so that when the user rotates the device to landscape The top space to superview is 50 Can this be done at design time? How can this be done at runtime? Well, if your 50 px for landscape and 100 for portrait can somehow be derived by relations to sibling subviews and fixed offsets to the bounds of superview, then yes, this can be done "at design time", and that's actually what auto layout is meant to be for. Otherwise you would need to have a reference to the constraint , then in

position a view in storyboard at 1/3 of screen size

∥☆過路亽.° 提交于 2019-12-03 16:07:31
问题 I'm trying to position a view in storyboard to always have it top edge at 1/3 of screen size. I have currently set a constraint to Top Layout Guide, but the constraint's constant is...well it is constant no matter which screen size it is used in, but I want it to be 1/3 of screen size. Can this be done entirely in storyboard? Thanks for answers Screenshot of current state: 回答1: Create a constraint between the view's top edge and the superview's bottom edge. Set the constraint's constant to

Can't programmatically set NSLayoutConstraint multiplier in swift… \"Cannot assign to the result of this expression

匆匆过客 提交于 2019-12-03 13:53:07
I am trying to programmatically set the constraint for a multiplier in swift, and when I set the value, it just gives me the error, "Cannot assign to the result of this expression"... I declared the NSLayoutConstraint with an IBOutlet, and then set the multiplier, same as I did with the constant for another, which works fine, but this one won't accept it... @IBOutlet weak var clockWidthConstraint: NSLayoutConstraint! override func updateViewConstraints() { super.updateViewConstraints() confirmTopConstraint.constant = 40.0 clockWidthConstraint.multiplier = 0.1 // Gives me the error! } Any ideas