create view with a red background of size 100 for width and height in swift

To create a view in Swift with a red background color of size 100 for both width and height, you can use the following code:

main.swift
let myView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
myView.backgroundColor = UIColor.red
109 chars
3 lines

This creates a view called 'myView' with a frame of CGRect(x: 0, y: 0, width: 100, height: 100) which sets the origin to (0,0) and the width and height to 100. We then set the background color of the view to UIColor.red which will give it a red background.

You can add this view to your current view hierarchy using:

main.swift
view.addSubview(myView)
24 chars
2 lines

Where view is the parent view that you want to add the myView to.

gistlibby LogSnag