ios - How do I programmatically make this auto layout? -
how make label auto layout devices.
golabel = uilabel(frame: cgrectmake(30, 100, 350, 100)) golabel.text = "game over" golabel.textcolor = uicolor.whitecolor() golabel.font = uifont(name: "applesdgothicneo-thin" , size: 70) self.view.addsubview(golabel)
let golabel = uilabel() golabel.settranslatesautoresizingmaskintoconstraints(false) let horizontalconstraint = nslayoutconstraint(item: golabel, attribute: nslayoutattribute.leading, relatedby: nslayoutrelation.equal, toitem: view, attribute: nslayoutattribute.leading, multiplier: 1, constant: 30) view.addconstraint(horizontalconstraint) let verticalconstraint = nslayoutconstraint(item: golabel, attribute: nslayoutattribute.top, relatedby: nslayoutrelation.equal, toitem: view, attribute: nslayoutattribute.top, multiplier: 1, constant: 100) view.addconstraint(verticalconstraint) let widthconstraint = nslayoutconstraint(item: golabel, attribute: nslayoutattribute.width, relatedby: nslayoutrelation.equal, toitem: nil, attribute: nslayoutattribute.notanattribute, multiplier: 1, constant: 350) golabel.addconstraint(widthconstraint) let heightconstraint = nslayoutconstraint(item: golabel, attribute: nslayoutattribute.height, relatedby: nslayoutrelation.equal, toitem: nil, attribute: nslayoutattribute.notanattribute, multiplier: 1, constant: 100) golabel.addconstraint(heightconstraint)
Comments
Post a Comment