Reputation: 1461
So I'm adding
var FBlogBut = FBSDKLoginButton()
loginView.addSubview(FBlogBut)
NSLayoutConstraint(item: FBlogBut, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 350 ).isActive = true
NSLayoutConstraint(item: FBlogBut, attribute: .centerX, relatedBy: .equal, toItem: loginView, attribute: .centerX, multiplier: 1, constant: 0 ).isActive = true
loginView.layoutIfNeeded()
So I'm not sure why the button is up in the top left corner and all the other items are working out ok..it at least should be 350 and cetnered.
Upvotes: 0
Views: 36
Reputation: 19912
There are two reasons.
First, you are only setting a CenterX and a Width. You'll need to specify a vertical constraint, either a top constraint or a CenterY.
The second is that by default translatesAutoresizingMaskIntoConstraints
will be true
, which means the view will set it's origin and size as constraints. This will mess your layout.
Just set it to false:
FBlogBut.translatesAutoresizingMaskIntoConstraints = false
PS. If you want to follow naming conventions, variable names are camel cased, which means the first character is lowercase. In this case your abbreviations are unnecessary, the button name could be fbLoginButton
and it's not too long. FBLogBut
makes it unclear if it's a login or logout button.
Upvotes: 1