Ahmad Naser Turnkey Ecosystem Ahmad Naser
October 30, 2019

SWIFT AUTOLAYOUT VISUAL FORMAT LANGUAGE PART2

Published in the Ahmad Naser ecosystem. Estimated reading time: 3 minutes.

screen-shot-2016-12-19-at-9-03-00-pm

        let View1 = UIView()
        View1.backgroundColor = UIColor.red
        view.addSubview(View1)
        view.addConstraintsWithFormat("H:|[v0]|", views: View1)

    
        let View2 = UIView()
        View2.backgroundColor = UIColor.green
        view.addSubview(View2)

        view.addConstraintsWithFormat("H:|[v0]|", views: View2)
        view.addConstraintsWithFormat("V:[v0(50)]-10-[v1(50)]", views: View1,View2)
     
        let View3 = UIView()
        View3.backgroundColor = UIColor.blue
        view.addSubview(View3)
        
        view.addConstraintsWithFormat("H:|[v0]|", views: View3)
        view.addConstraintsWithFormat("V:[v0]-10-[v1(100)]", views: View2,View3)
        
        
        let View4 = UIView()
        View4.backgroundColor = UIColor.yellow
        view.addSubview(View4)
        
        view.addConstraintsWithFormat("H:|[v0]|", views: View4)
        view.addConstraintsWithFormat("V:[v0]-10-[v1(50)]", views: View3,View4)

 

screen-shot-2016-12-19-at-9-43-22-pm

 
        
        let View1 = UIView()
        View1.backgroundColor = UIColor.red
        view.addSubview(View1)
        view.addConstraintsWithFormat("H:|[v0]|", views: View1)

    
        let View2 = UIView()
        View2.backgroundColor = UIColor.green
        view.addSubview(View2)

        view.addConstraintsWithFormat("H:|[v0]|", views: View2)
        view.addConstraintsWithFormat("V:[v0(50)]-10-[v1(40)]", views: View1,View2)
     
        //add label to subview
        let label2 = UILabel(frame: View2.bounds)
        label2.backgroundColor = UIColor.brown
        
        label2.textColor = UIColor.white
        label2.backgroundColor = UIColor.orange
        label2.text = "HelloHelloHelloHello"
        label2.frame = CGRect(x: 10, y: 0, width: 200, height: 40)
        label2.textAlignment = .left
        label2.font = label2.font.withSize(16)
        //label2.shadowColor = UIColor.black
        //label2.shadowOffset = CGSize(width: 1, height: 1)
        View2.addSubview(label2)
        
        
        
        let View3 = UIView()
        View3.backgroundColor = UIColor.blue
        view.addSubview(View3)
        
        view.addConstraintsWithFormat("H:|[v0]|", views: View3)
        view.addConstraintsWithFormat("V:[v0]-10-[v1(80)]", views: View2,View3)
        
        
        
        //add label to subview
        let label3 = UILabel(frame: View3.bounds)
        label3.backgroundColor = UIColor.brown
        
        label3.textColor = UIColor.white
        label3.text = "Mohammad Assaf endorses Reach Education Fund and Run4Palestine"
        label3.frame = CGRect(x: 10, y: 0, width:view.frame.width - 20, height: 80)
        label3.numberOfLines = 2
        label3.textAlignment = .left
        label3.font = label3.font.withSize(18)
        label3.shadowColor = UIColor.black
        label3.shadowOffset = CGSize(width: 1, height: 1)
        View3.addSubview(label3)
        
        let View4 = UIView()
        View4.backgroundColor = UIColor.yellow
        view.addSubview(View4)
        
        view.addConstraintsWithFormat("H:|[v0]|", views: View4)
        view.addConstraintsWithFormat("V:[v0]-10-[v1(50)]", views: View3,View4)
        
        
    
        
    //add label to subview
        let label = UILabel(frame: View4.bounds)
        label.backgroundColor = UIColor.brown
        
        label.textColor = UIColor.white
        label.text = "HelloHelloHelloHello"
        label.frame = CGRect(x: 10, y: 0, width:view.frame.width, height: 40)
        label.textAlignment = .left
        label.font = label.font.withSize(14)
        label.shadowColor = UIColor.black
        label.shadowOffset = CGSize(width: 1, height: 1)
        View4.addSubview(label)
        

Now set background color to clear (transparent)

screen-shot-2016-12-19-at-9-46-33-pm

        let View1 = UIView()
        View1.backgroundColor = UIColor.clear
        view.addSubview(View1)
        view.addConstraintsWithFormat("H:|[v0]|", views: View1)

    
        let View2 = UIView()
        View2.backgroundColor = UIColor.clear
        view.addSubview(View2)

        view.addConstraintsWithFormat("H:|[v0]|", views: View2)
        view.addConstraintsWithFormat("V:[v0(50)]-10-[v1(40)]", views: View1,View2)
     
        //add label to subview
        let label2 = UILabel(frame: View2.bounds)
        label2.backgroundColor = UIColor.clear
        
        label2.textColor = UIColor.white
        label2.backgroundColor = UIColor.orange
        label2.text = "HelloHelloHelloHello"
        label2.frame = CGRect(x: 10, y: 0, width: 200, height: 40)
        label2.textAlignment = .left
        label2.font = label2.font.withSize(16)
        //label2.shadowColor = UIColor.black
        //label2.shadowOffset = CGSize(width: 1, height: 1)
        View2.addSubview(label2)
        
        
        
        let View3 = UIView()
        View3.backgroundColor = UIColor.clear
        view.addSubview(View3)
        
        view.addConstraintsWithFormat("H:|[v0]|", views: View3)
        view.addConstraintsWithFormat("V:[v0]-10-[v1(80)]", views: View2,View3)
        
        
        
        //add label to subview
        let label3 = UILabel(frame: View3.bounds)

        
        label3.textColor = UIColor.white
        label3.text = "Mohammad Assaf endorses Reach Education Fund and Run4Palestine"
        label3.frame = CGRect(x: 10, y: 0, width:view.frame.width - 20, height: 80)
        label3.numberOfLines = 2
        label3.textAlignment = .left
        label3.font = label3.font.withSize(18)
        label3.shadowColor = UIColor.black
        label3.shadowOffset = CGSize(width: 1, height: 1)
        View3.addSubview(label3)
        
        let View4 = UIView()
        View4.backgroundColor = UIColor.clear
        view.addSubview(View4)
        
        view.addConstraintsWithFormat("H:|[v0]|", views: View4)
        view.addConstraintsWithFormat("V:[v0]-10-[v1(50)]", views: View3,View4)
        
        
    
        
    //add label to subview
        let label = UILabel(frame: View4.bounds)
        
        label.textColor = UIColor.white
        label.text = "HelloHelloHelloHello"
        label.frame = CGRect(x: 10, y: 0, width:view.frame.width, height: 40)
        label.textAlignment = .left
        label.font = label.font.withSize(14)
        label.shadowColor = UIColor.black
        label.shadowOffset = CGSize(width: 1, height: 1)
        View4.addSubview(label)

screen-shot-2016-12-19-at-9-46-33-pm screen-shot-2016-12-19-at-10-01-53-pm screen-shot-2016-12-19-at-10-03-24-pm

screen-shot-2016-12-19-at-10-06-29-pm

screen-shot-2016-12-19-at-10-19-37-pm

Leave a Reply

Your email address will not be published. Required fields are marked *