Swift CGRectMake Center button -


i'm programming button swift spriest project. location of button messing up. wan in middel goes random place.

let button = uibutton(type: .system) // let preferred on var here button.frame = cgrectmake(self.frame.width / 2, self.frame.height / 2, 100, 50) print(self.frame.height / 2) button.backgroundcolor = uicolor.greencolor() button.settitle("button", forstate: uicontrolstate.normal) self.view!.addsubview(button) 

i don't know why cgpoint works can't use cgpoint here.

try this...

button.frame = cgrectmake(     self.view.center.x - (widthofbutton / 2),      self.view.center.y - (heightofbutton / 2),      widthofbutton,      heightofbutton) 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -