IOS TOPICS

IOS Introduction
Swift UI Label
Swift UI Button
Swift UI Text Field
Swift UI Slider
Swift UI Switch
Swift UI Stepper
Swift UI Date Picker
Swift UI Segmented Control
Views
Table View
Collection Views
SCROLL VIEW
iOS Content View
iOS View Controllers
iOS Bar interface
iOS Navigation interface
iOS Architect Pattern
iOS Libraries
iOS Web request and parsing
iOS user defaults
iOS Coredata and database

View Hierarchy


How to initialise and add specific details about the view rectangle ?

We can create an instance of a view using the UIView initialiser and use the frame property to define the height, width and the x and y positions of the view (which is basically a rectangle). Finally we have to add it as a subview to a visible view so that we can see it

Code:

import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = colorLiteral(red: 0.1019607857, green: 0.2784313858, blue: 0.400000006, alpha: 1) //use color literal to get a variety of color options let newView = UIView(frame: CGRect(x: 10, y: 100, width: 300, height: 50)) newView.backgroundColor = UIColor.white view.addSubview(newView) } }

Output:

ios output