通过使用单个按钮iOS Swift并排显示多个按钮

时间:2019-05-16 09:26:07

标签: ios swift xcode

在stackoverflow中,仅显示2或3个按钮,即通过情节提要

图片:https://ibb.co/gSFQX2k

2 个答案:

答案 0 :(得分:1)

 var consolebtn = [UIButton]()
 var x = Int()
 x = 0

 @IBAction func pushButton(sender: UIButton) {
     let btn = UIButton() 
     btn.frame = CGRect(x:x, y:10, width:10, height:10)
     btn.setTitle("Button Title",for: .normal)
     consolebtn.append(btn)
     view.addSubview(btn)  
     x += 20 // 10 is width & 10 is gap between two button
 }

答案 1 :(得分:0)