通过故事板中的IBOutlet更改UIView的框架

时间:2014-10-20 06:02:07

标签: ios swift

@IBOutlet weak var outletView: UIView! //Referencing Outlet connected
override func viewDidLoad() {

    super.viewDidLoad()
    //not working
    outletView.frame = CGRectMake(100, 100, 100, 100)

    //working
    var view = UIView();
    view.frame = CGRectMake(0, 20, 100, 100);
    self.view.addSubview(view);
}

如何将@IBoutlet视图的帧编辑为普通的UIView实例?


我解决了它以删除StoryBoard检查器上的Use Size Classes

1 个答案:

答案 0 :(得分:0)

当您在frame方法中设置ViewDidload时,它首先会分配您在ViewDidload中设置的框架,然后应用Storyboard Constraints你的constraints被覆盖了。

要更改constraints,请constraints方法应用ViewDidAppear并将反映

override func viewDidAppear(animated: Bool) 
{

        outletView.frame = CGRect(x: 100, y: 100, width: 200, height: 400)

}