【问题标题】:Insert a button and load a second view programmatically using Swift使用 Swift 以编程方式插入按钮并加载第二个视图
【发布时间】:2014-07-01 15:47:21
【问题描述】:

我想以编程方式向视图添加一个按钮,然后当用户按下此按钮时,加载名为“Giraanam”的第二个视图。我设法编写代码来显示按钮,但我不知道如何让它加载第二个视图...谁能帮帮我吗?

到目前为止我尝试的代码是:

let button = UIButton.buttonWithType(UIButtonType.System) as UIButton
button.frame = CGRectMake(20, 25, 34, 34)
button.backgroundColor = UIColor.greenColor()
button.setBackgroundImage(UIImage(named:"Back_Resultados.png"),forState: UIControlState.Normal)
button.addTarget(self, action: "Giraanam",  forControlEvents: UIControlEvents.TouchUpInside)
self.addSubview(button)

【问题讨论】:

    标签: ios uibutton swift


    【解决方案1】:

    您需要实现函数Giraanam 来创建新视图并添加到另一个视图。示例:

    func Giraanam() {
    
       let newView = UIView()
    
    // customise your view
    
       self.view.addSubview(newView)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-17
      • 1970-01-01
      • 1970-01-01
      • 2020-12-05
      • 2012-11-19
      • 1970-01-01
      • 2013-07-17
      • 1970-01-01
      相关资源
      最近更新 更多