ios - Programmatically using constraints on a button that is also programmatically made -


i'm trying facebook login button (top center of screenshot) below "register or login button" using constraints, i'm not sure constraints use , how use them. i'm quite new swift 3 , have not done constraint programmatically yet, welcomed! used x , y position in cgrect place button, noticed on different device, button not in same place, i'm trying use constraints now.

it looks this:

enter image description here

this code regarding button in viewdidload:

let fbloginbutton = fbsdkloginbutton()  view.addsubview(fbloginbutton)  fbloginbutton.frame = cgrect(x: 0, y: 0, width: view.frame.width -          100, height: 40)  self.view.addsubview(fbloginbutton)  fbloginbutton.center.x = view.frame.width/2 

i tried doing:

let verticalspace = nslayoutconstraint(     item: self, attribute: .bottom, relatedby: .equal, toitem: fbloginbutton,     attribute: .bottom, multiplier: 0.75, constant: 0) 

but led me error:

constraint items must each instance of uiview, or uilayoutguide.

try code had added button "send" programatically below button "show alert" added using storyboard

@iboutlet weak var showalertbutton: uibutton!  func addbutton(){       let sendbutton = uibutton(type: .system)     sendbutton.settitle("send", for: uicontrolstate())     sendbutton.translatesautoresizingmaskintoconstraints = false     self.view.addsubview(sendbutton)      sendbutton.leftanchor.constraint(equalto: showalertbutton.leftanchor, constant: 0).isactive = true     sendbutton.rightanchor.constraint(equalto: showalertbutton.rightanchor, constant: 0).isactive = true     sendbutton.topanchor.constraint(equalto: showalertbutton.bottomanchor, constant: 10).isactive = true     sendbutton.widthanchor.constraint(equaltoconstant: 80).isactive = true     sendbutton.heightanchor.constraint(equalto: showalertbutton.heightanchor).isactive = true   } 

enter image description here


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -