Swlist从Plist分配按钮位置

时间:2015-01-13 12:45:52

标签: swift ios8

我在我的功能中添加了约束

func CreateButtonWithIndex(var index:Int) {

    let path = loadPath()
    var data = NSMutableDictionary(contentsOfFile: path)
    let newButton = UIButton.buttonWithType(UIButtonType.System) as UIButton       newButton.setTranslatesAutoresizingMaskIntoConstraints(false)

    self.view.addSubview(newButton)

   let newButtonConstraintL = NSLayoutConstraint(item: newButton, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 50)

    let newButtonConstraintH = NSLayoutConstraint(item: newButton, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 50)

 //   Read from Plist the coordinate

    var reloadCoordX:[String] = data!.valueForKey("\(strDaPassare) X") as[String]
    var reloadCoordY:[String] = data!.valueForKey("\(strDaPassare) Y") as[String]
    var coordX: Int = ("\(reloadCoordX[index-1])").toInt()!
    var coordY: Int = ("\(reloadCoordY[index-1])").toInt()!

    // Add Constraint

    newButtonConstraintX = NSLayoutConstraint(item: newButton, attribute: .CenterX, relatedBy: .Equal, toItem: view, attribute: .CenterX, multiplier: 1, constant: CGFloat(coordX))

    newButtonConstraintY = NSLayoutConstraint(item: newButton, attribute: .CenterY, relatedBy: .Equal, toItem: view, attribute: .CenterY, multiplier: 1, constant: CGFloat(coordY))

}

没关系!!!!但是这需要作为UIView的参考中心,它可以用于newButtonConstraintX和newButtonConstraintY的值。但是如果我想为左上角设置newButtonConstraintX和newButtonConstraintY的属性?

0 个答案:

没有答案