Swift iOS输入法开发( 六 )

  • ...
  • // set the button 50 points to the left (-) of the horizontal center
  • var dotCenterXConstraint = NSLayoutConstraint(item: dotButton, attribute: .CenterX, relatedBy: .Equal, toItem: view, attribute: .CenterX, multiplier: 1.0, constant: -50)
  • view.addConstraints([dashCenterXConstraint, dashCenterYConstraint])

  • 回删
    当被按下时,这个删除按钮会通过,使用删除字符 。这个布局约束会和对称(.Left -> .Right, .->.Top)
    1. func addDelete() {
    2. deleteButton = UIButton.buttonWithType(.System) as UIButton
    3. deleteButton.setTitle(" Delete ", forState: .Normal)
    4. deleteButton.sizeToFit()
    5. deleteButton.setTranslatesAutoresizingMaskIntoConstraints(false)
    6. deleteButton.addTarget(self, action: "didTapDelete", forControlEvents: .TouchUpInside)
    7. deleteButton.backgroundColor = UIColor(white: 0.9, alpha: 1)
    8. deleteButton.layer.cornerRadius = 5
    9. view.addSubview(deleteButton)
    10. var rightSideConstraint = NSLayoutConstraint(item: deleteButton, attribute: .Right, relatedBy: .Equal, toItem: view, attribute: .Right, multiplier: 1.0, constant: -10.0)