我试着做自动布局,使按钮出现在边缘,但在iphone 5它的边缘和iphone 6它是在中间区域。为什么按钮不在两侧的电话?
next = UIButton()
let me = "next.png"
next.setImage(UIImage(named: me), forState: .Normal)
next.frame = CGRectMake(250, 370, 40, 40)
next.setTranslatesAutoresizingMaskIntoConstraints(false)
next.addTarget(self,action: "nexter:", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(next)
let horizontalConstraintnext = NSLayoutConstraint(item: next, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Leading, multiplier: 1, constant: 285)
view.addConstraint(horizontalConstraintnext)
let verticalConstraintnext = NSLayoutConstraint(item: next, attribute: NSLayoutAttribute.Top, relatedBy: NSLayoutRelation.Equal, toItem: view, attribute: NSLayoutAttribute.Top, multiplier: 1, constant: 350)
view.addConstraint(verticalConstraintnext)
let widthConstraintnext = NSLayoutConstraint(item: next, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 40)
next.addConstraint(widthConstraintnext)
let heightConstraintnext = NSLayoutConstraint(item: next, attribute: NSLayoutAttribute.Height, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: 40)
next.addConstraint(heightConstraintnext)
由于设备具有不同的宽度。 – nhgrif