Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Auto Layout Using Visual Format Language In Swift

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 529
    Comment on it

    Hi All,

    You can add auto layout constraints by using Storyboard Interface OR by adding constraints dynamically. There are three ways to add constraint dynamically (as per Apple Inc.)


    Visual Format Language is one of the way is used to add autolayout constraints dynamically.


    Visual Format Language Example :-

    let new_view:UIView! = UIView(frame: CGRectMake(20, 20, 100, 100));
            new_view.backgroundColor = UIColor.redColor();
            new_view.translatesAutoresizingMaskIntoConstraints = false
            view.addSubview(new_view);
    
    
    
            let views = ["view": view, "newView": new_view]
            let horizontalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:|-[newView(100)]", options: NSLayoutFormatOptions.AlignAllLeft, metrics: nil, views: views)
            view.addConstraints(horizontalConstraints)
            let verticalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|-(20)-[newView(100)]", options: NSLayoutFormatOptions.AlignAllTop, metrics: nil, views: views)
            view.addConstraints(verticalConstraints)
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: