Trevor Wood Trevor Wood - 2 months ago 10
iOS Question

Are iOS "views" and HTML divs similar?

So I'm pretty new to iOS Apps.

I found that placing a view in my app and sizing it to my needs is pretty similar to divs in HTML. Should I be using them this way?

Here's an example of a place I want to use a view.

enter image description here

I want to fill that in, should I be using a view here? or something more semantical?

end result with a view:

enter image description here

Answer

If you want to set a rectangle somewhere you could definitely use an UIView(), If you´re using your storyboard make sure to set the right constraint and if you´re doing it programmatically you could do the following to get it work with all phone sizes:

Swift 3.0:

let screen = UIScreen.main.bounds

let anotherView = UIView(frame: CGRect(x: 0, y: 0, width: screen.width, height: 45))
anotherView.backgroundColor = UIColor.blue
view.addSubview(anotherView)

Swift 2.x:

let screen = UIScreen.mainScreen().bounds

let anotherView = UIView(frame: CGRect(x: 0, y: 0, width: screen.width, height: 45))
anotherView.backgroundColor = UIColor.blueColor()
view.addSubview(anotherView)
Comments