ios - Add button only in Code? -
I'm just trying to add a button to the code in Xcode simulator, it works not only on my device but also Fatal error: unexpectedly unwrapping an optional value while zero found
My code:
@ Ibsultile Weak Play Button: UI Button! Override function viewDidLoad () {image.updatedDidLoad () go image = UIImage (name: "playButton.png") UIImage playButton = UIButton.buttonWithType (UIButtonType.System) UIButton playButton.frame = CGRectMake (10, 10, 100 As, 100) // crash here playButton.center = CGPointMake (self.frame.width / 2, self.frame.height / 1.7) playButton.addTarget (self, action is: "transition:", forControlEvents: UIControlEvents TouchUpInside) playButton SetBackgroundImage (Image, forState: UIControlState.Normal) self.view? .addSubview (playButton)} Can someone help me?
It does not make sense - if you're using @iBotlett, it means that the storyboard Your button has been created so you do not have to start it:
go image = UIImage (name: "playButton.png") UIImage playButton = UIButton.buttonWithType (UIButtonType .system) as UIButton playButton.frame = CGRectMake (10, 10, 100, 100) // crash here is playButton.center = CGPointMake (self.frame.width / 2, self.frame.height / 1.7 ) PlayButton.addTarget (self, action: "transition:", forControlEvents: UICon trolEvents.TouchUpInside) playButton.setBackgroundImage (image, forState: UIControlState.Normal) self.view .addSubview (playButton) set above and above the code set in the storyboard Do @ ebayings should be a different method that should be accustomed to your button inside your touch-up in your storyboard.
Comments
Post a Comment