create a view with a red background of size 100 by 100 in swift

To create a view with a red background color of size 100 by 100 in Swift, you can use the UIView class and set its backgroundColor and frame properties:

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

You can then add this view to your view hierarchy with:

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

Note: view here refers to the view controller's view, assuming you are creating this view in a view controller.

gistlibby LogSnag