如何将多个SegmentedControl加载到ViewController中

时间:2017-12-04 11:36:25

标签: ios swift

我正在尝试将多个SegmentedControls加载到Xcode上的一个ViewController中。下面是按钮。 Buttons

当我点击其中一个按钮时,我想要加载SegmentedControl。 SegmentedControl

这些SegmentedControls将加载到ViewController上。有没有办法让这种情况发生?

我目前的代码如下:

    @IBAction func action(_ sender: Any) {

    //let url = URL(string: sender.accessibilityIdentifier!)!

    let alertController = UIAlertController(title: (sender as AnyObject).accessibilityLabel, message: (sender as AnyObject).accessibilityHint, preferredStyle: .actionSheet)

    let HSAction = UIAlertAction(title: "Upper Building", style: .default) { action in

        DispatchQueue.main.async {
            self.performSegue(withIdentifier: "one", sender: nil)
        }


        //UIApplication.shared.open(url, options: [:], completionHandler: nil)
    }
    alertController.addAction(HSAction)
    }

1 个答案:

答案 0 :(得分:0)

移动到另一个视图控制器后,您可以使用多个按钮创建segmentedcontrol,如下所示。

segmentedControl = UISegmentedControl (items: ["First","Second","Third"])
    segmentedControl.frame = CGRectMake(60, 250,200, 30)
    segmentedControl.selectedSegmentIndex = 0
    segmentedControl.addTarget(self, action: "segmentedControlAction:", forControlEvents: .ValueChanged)
    self.view.addSubview(segmentedControl)