To create a view of 50 by 50 size with a green background programmatically, you can follow these steps:
main.swift479 chars21 lines
In this code, we create a UIView
instance named myView
and set its frame to a width of 50
and a height of 50
. We set the background color of the view to green by setting its backgroundColor
property to UIColor.green
. Finally, we add the view to the view hierarchy using the addSubview
method on self.view
.
Note that this code creates the new view in the viewDidLoad()
method of a UIViewController
, but you can also create the view in a different method or class if desired.
gistlibby LogSnag