swift - How do I change the CGRect to buttons? -
i used rectangles test out program need make them buttons. how programmatically?
import uikit
class interestviewcontroller: uiviewcontroller {
var squareview: uiview! var square: uiview! var frogs: uiview! var colson: uiview! var wwdc: uiview! var gravity: uigravitybehavior! var animator: uidynamicanimator! var collision: uicollisionbehavior! override func viewdidload() { super.viewdidload() squareview = uiview(frame: cgrectmake(100, 100, 100, 100)) view.addsubview(squareview) animator = uidynamicanimator(referenceview: view) squareview.backgroundcolor = uicolor.blackcolor() gravity = uigravitybehavior(items: [squareview]) animator.addbehavior(gravity) collision = uicollisionbehavior(items: [squareview]) collision.translatesreferenceboundsintoboundary = true animator.addbehavior(collision) // additional setup after loading view. } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. }
}
question: how programmatically?
short answer: don't. create buttons in ib. it's easier code first time, , way, waaaaay easier update , maintain. learn use ib. it's huge timesaver.
if bound , determined things hard way, you'll need use 1 of uibutton class initializers, buttonwithtype. you'd set frame , other attributes you're doing squareview.
Comments
Post a Comment