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
Post a Comment