Customising view
Transparency: To alter the transparency of a view use
code:
< view name > .alpha = < transparency in decimals >
Example: Setting the newView to 70% transparency (effect cascades to subview newView2)
Code:
view.backgroundColor = colorLiteral(red: 0.1019607857, green: 0.2784313858, blue: 0.400000006, alpha: 1) //use colorliteral to get a variety of color options
let newView = UIView(frame: CGRect(x: 10, y: 100, width: 300, height: 50))
newView.clipsToBounds = true
newView.alpha = 0.7
let newView2 = UIView(frame: CGRect(x: 6, y: 6, width: 400, height: 100))
newView.backgroundColor = UIColor.white
newView2.backgroundColor = UIColor.black
view.addSubview(newView)
newView.addSubview(newView2)
Output:
To hide a view
Use: < view name.isHidden = True
Code:
view.backgroundColor = colorLiteral(red: 0.1019607857, green: 0.2784313858, blue: 0.400000006, alpha: 1) //use colorliteral to get a variety of color options
let newView = UIView(frame: CGRect(x: 10, y: 100, width: 300, height: 50))
newView.clipsToBounds = true
let newView2 = UIView(frame: CGRect(x: 6, y: 6, width: 400, height: 100))
newView.backgroundColor = UIColor.white
newView2.backgroundColor = UIColor.black
view.addSubview(newView)
newView.addSubview(newView2)
newView2.isHidden = true
Output: