ios - 按下按钮到下一个 "storyboard"在 Swift 中以编程方式设计 UI

标签 ios swift uibutton

let signupButton = UIButton.buttonWithType(UIButtonType.System) as! UIButton
signupButton.setTranslatesAutoresizingMaskIntoConstraints(false)
signupButton.setBackgroundImage(UIImage(named: "signupButton"), forState: .Normal)
signupButton.setTranslatesAutoresizingMaskIntoConstraints(false)
signupButton.setTitleColor(UIColor(red: 1, green: 1, blue: 1, alpha: 1), forState: .Normal)
signupButton.setTitle(NSLocalizedString("SIGN UP", comment: ""), forState: .Normal)

self.view.addSubview(signupButton)
// width constraint
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:[SignupButton(==149)]", options: .DirectionLeadingToTrailing, metrics: nil, views: ["SignupButton": signupButton]))

// height constraint
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[SignupButton(==60)]", options: .DirectionLeadingToTrailing, metrics: nil, views: ["SignupButton": signupButton]))

self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-464.5-[signupButton]-142.5-|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["signupButton": signupButton]))
self.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-196-[signupButton]-30-|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["signupButton": signupButton]))

按下此按钮时,我需要它实质上推送到另一个 ViewController。

最佳答案

您必须使用代码编写按钮操作

signupButton.addTarget(self, action: "pressed:", forControlEvents: .TouchUpInside)

然后创建一个名为pressed的函数

func pressed (sender:UIButton!) {

//write the code for changing view controller

}

关于ios - 按下按钮到下一个 "storyboard"在 Swift 中以编程方式设计 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31376564/

相关文章:

ios - 如何使用swift在折线图中显示json数据

ios - 创建一个 swift 泛型数组

ios - 使用 beginUpdates/endUpdates 从 tableview 中删除行

ios - UIButton懒惰将状态从正常更改为突出显示

ios - xcode、macbook 和复制缓冲区插入 iPhone?

iphone - 从 UIViewController 绘制一条线

ios - 带有 UITextField : Trouble with Delegates and Dequequing 的自定义 Xib UITableViewCell

swift - MTLCreateSystemDefaultDevice() 在装有 iOS 10.3 的 iPad 上返回 nil

iPhone SDK - UIButton 在自定义 View 中不起作用

iphone - 如何动态更改 UIButton 的位置