2016-07-23 14 views
1

未解決の識別子は以下の7行目に表示されます:スウィフトエラー:私はこのコードを使用して<code>UIView</code>にスウィフトでプログラムいくつかの制約を適用する必要がありますが、私は</p> <blockquote> <p>Unresolved Identifier for NSLayoutAttributeWidth and NSLayoutRelationEqual.</p> </blockquote> <p>エラーのエラーを受けている「NSLayoutAttributeWidth」

func setViews(){ 
    addSubview(aGradeView) 
    addSubview(bGradeView) 

    addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-280-[viewA(==viewB)]-0-[viewB]-0-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["viewA": aGradeView, "viewB": bGradeView])) 

    let constraint: NSLayoutConstraint = NSLayoutConstraint(item: aGradeView, attribute: NSLayoutAttributeWidth, relatedBy: NSLayoutRelationEqual, toItem: bGradeView, attribute: NSLayoutAttributeWidth, multiplier: 1.0, constant: 5.0) 

    /*addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[viewA]-0-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["viewA": aGradeView])) 
    addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-0-[viewB]-0-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["viewB": bGradeView])) 
    */ 
} 

let aGradeView: UIView = { 
    let view = UIView() 
    view.backgroundColor = UIColor(red: 207.0/255.0, green: 240.0/255.0, blue: 158.0/255.0, alpha: 255.0) 
    view.translatesAutoresizingMaskIntoConstraints = false 
    view.setconstr 
    return view 
}() 

let bGradeView: UIView = { 
    let view = UIView() 
    view.backgroundColor = UIColor(red: 150.0/255.0, green: 240.0/255.0, blue: 158.0/255.0, alpha: 255.0) 
    view.translatesAutoresizingMaskIntoConstraints = false 
    return view 
}() 

UIKitをインポートしましたが、プロジェクトを数回はクリーニングしようとしましたが、役に立たなかった。この問題を解決するにはどうすればよいですか?迅速で

答えて

1

、あなただけの代わりにNSLayoutAttributeWidth.Widthを使用するか、だからあなたの制約が完全に働いたこの

let constraint = NSLayoutConstraint(item: aGradeView, attribute: .Width, relatedBy: .Equal, toItem: bGradeView, attribute: .Width, multiplier: 1.0, constant: 5.0) 
+1

ようにする必要がありNSLayoutAttribute.Width

を使用することができます! – BlackDeveraux

+1

うれしいよ:) –

関連する問題

 関連する問題