将多个按钮放置在一类中(swift4)

时间:2018-08-23 04:14:52

标签: class button constraints swift4 multiple-inheritance

下面的代码正尝试使用一个类,这是因为使用多个按钮来定位中心文本对齐。有问题的按钮是a1和a2。

%>% set_names(~sub('^V(\\d+)$', 'new\\1', .x))

VIEWCONTROLLER感谢

class ViewController: UIViewController {
var a1 = thanks()
var a2 = thanks()
 override func viewDidLoad() {
    super.viewDidLoad()
    ax.isHidden = true

    jx.isHidden = true

    a1.addTarget(self, action: #selector(textFieldDidChange(_:)), for: .touchDown)

    a1.translatesAutoresizingMaskIntoConstraints = false
    let leadingc2bcxf3s4s3s5s6s7s9 = a1.widthAnchor.constraint(equalToConstant: 80)
    let  trailingC2bcxf3s4s3s5s6s7s9 = a1.heightAnchor.constraint(equalToConstant: 50)
    let topc2bcxf3s4s3s5s6s7s9 = a1.centerXAnchor.constraint(equalTo: self.view.centerXAnchor, constant: -50)
    let bottomc2bcxf3s4s3s5s6s7s9 = a1.centerYAnchor.constraint(equalTo: self.view.centerYAnchor, constant: -250)

    a = [leadingc2bcxf3s4s3s5s6s7s9,trailingC2bcxf3s4s3s5s6s7s9 ,topc2bcxf3s4s3s5s6s7s9,bottomc2bcxf3s4s3s5s6s7s9]

    NSLayoutConstraint.activate(a)

    a2.translatesAutoresizingMaskIntoConstraints = false
    let leadingc2bcxf3s4s3s5s6s7s9a2 = a2.widthAnchor.constraint(equalToConstant: 80)
    let  trailingC2bcxf3s4s3s5s6s7s9a2 = a2.heightAnchor.constraint(equalToConstant: 50)
    let topc2bcxf3s4s3s5s6s7s9a2 = a2.centerXAnchor.constraint(equalTo: self.view.centerXAnchor, constant: 50)
    let bottomc2bcxf3s4s3s5s6s7s9a2 = a2.centerYAnchor.constraint(equalTo: self.view.centerYAnchor, constant: -250)

    b = [leadingc2bcxf3s4s3s5s6s7s9a2,trailingC2bcxf3s4s3s5s6s7s9a2 ,topc2bcxf3s4s3s5s6s7s9a2,bottomc2bcxf3s4s3s5s6s7s9a2]

    NSLayoutConstraint.activate(b)}

我收到一个编译错误。当代码通过模拟器运行时,代码崩溃。

0 个答案:

没有答案